Assume following declaration: int i1=11, i2=12; double d1=3.45, d2= 6.78; 1)writ
ID: 3569284 • Letter: A
Question
Assume following declaration:
int i1=11,
i2=12;
double d1=3.45,
d2= 6.78;
1)write the declaration for variable p1 and p2 whose values will be adress of memory location in which a double can be stored.
2)write statement to assign the address of d1 and d2 to the variable p1 and p2.
3)write statement to assign the address of i1 to variable p2.
4) write declaration that initialize variable ptr1 and ptr2 with addresses of i1 and i2 , respectiverly.
5)write statement that will make variable p1 and p2 of question#1 point to the same memory location.
6)write a statement that will copy the value stored in the memory location ointed to by ptr2 into the memory location pointed to by ptr1 and ptr2 as in question 4.
7) write statement that use the variables p1 and p2 of question 2, but no the variable d1 and d2, to interchange the value of d1 and d2.
8) using typeded, create an alias type Charpointer for pointers to type char.
Explanation / Answer
1) The declaration for variable p1 and p2 whose values contains the address of memory location
in which a double can be stored:
double *p1,*p2;
2) The statements to assign the address of d1 to the variable p1 and address of d2 to the variable p2:
p1=&d1;
p2=&d2;
3) The statement to assign the address of i1 to variable p2:
int *p2;
p2=&i1;
4) The declaration that initialize variable ptr1 with addresses of i1 and ptr2 with addresses of i2:
int i1=11, i2=12;
int *ptr=&i1, *ptr2=&i2;
5) The statement that will make variable p1 and p2 to point to same address:
p1=p2;
6) The statement that will make variable ptr1and ptr2 to point to same address:
ptr1=ptr2;
7) Swapping using pointer variables:
int temp;
temp = *p1;
*p2 = *p1;
*p1 = temp;
8)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.