Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program pointer Tester.c to experiment with pointers. Implement the fol

ID: 3683117 • Letter: C

Question

Create a program pointer Tester.c to experiment with pointers. Implement the following steps: 1. Declare three integer variables a, b and c. Initialize them to 0,100 and 225 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int *pA = &a;, *pB = &b;, *p; 4. Print the value of each pointer and the value it points to. What is the value of (*p)? 5. Print the value of each pointer and the value it points to using the "%p" specified. 6. Run your program multiple times. Does any of the values *pA, *pB or *p change? Does any of the values pA, pB or p change? 7. Change the value that p points to to 50. 8. Set p to point to a; 9. Find 3 different ways to change the value of a to 92; 10. Add the following to your code: 11. What is the effect of the previous statements? Verify by printing the values of p, pA, pB, *p, *pA, *pB, a, b, &a;, &b; after every step. 12. Declare an array z of 10 integers and initialize its elements to 0,1, 2,.... 13. Print the address of each element in the array 14. Print the values of z, (z+1), (z+2)...... (z+12). 15. Add the following: *(z+3)++. What does this statement do? 16. Add the following: int * t = z; 17. Print t, t+1, t+2, t+3, t+4. 18. Set t to t+5. Print t, *t.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

int main() {

//1
int a=0,b=100,c=225;

//2
printf("a = %d at address %d ", a, &a);
printf("b = %d at address %d ", b, &b);
printf("c = %d at address %d ", c, &c);

//3
int *pA = &a, *pB = &b, *p;

//4
printf("value of pointer pA = %d and it points to %d ", pA, *pA);
printf("value of pointer pB = %d and it points to %d ", pB, *pB);
//printf("value of pointer p = %d and it points to %d ", p, *p); //this gives segment fault

//5
printf("value of pointer pA = %p and it points to %p ", pA, *pA);
printf("value of pointer pB = %p and it points to %p ", pB, *pB);
//printf("value of pointer p = %p and it points to %p ", p, *p); //this gives segment fault

//6
//value of pA, pB, p changes. *pA and *pB remains constant. *p gives segment fault

//7
//*p = 50; //this gives segment fault

//8
p = &a;

//9
a = 92;
*p = 92;
*pA = 92;

//10 and 11
p = pA;
*p = 22;
printf("value of pointer pA = %d and it points to %d ", pA, *pA);
printf("value of pointer pB = %d and it points to %d ", pB, *pB);
printf("value of pointer p = %d and it points to %d ", p, *p);
printf("Value of a = %d and &a = %d ", a, &a);
printf("Value of b = %d and &a = %d ", b, &b);
p = pB;
*p = 18;
printf("value of pointer pA = %d and it points to %d ", pA, *pA);
printf("value of pointer pB = %d and it points to %d ", pB, *pB);
printf("value of pointer p = %d and it points to %d ", p, *p);
printf("Value of a = %d and &a = %d ", a, &a);
printf("Value of b = %d and &a = %d ", b, &b);
p = &b;
*p = 108;
printf("value of pointer pA = %d and it points to %d ", pA, *pA);
printf("value of pointer pB = %d and it points to %d ", pB, *pB);
printf("value of pointer p = %d and it points to %d ", p, *p);
printf("Value of a = %d and &a = %d ", a, &a);
printf("Value of b = %d and &a = %d ", b, &b);
p = pA;
*p = 2;
printf("value of pointer pA = %d and it points to %d ", pA, *pA);
printf("value of pointer pB = %d and it points to %d ", pB, *pB);
printf("value of pointer p = %d and it points to %d ", p, *p);
printf("Value of a = %d and &a = %d ", a, &a);
printf("Value of b = %d and &a = %d ", b, &b);
*p = &a;
printf("value of pointer pA = %d and it points to %d ", pA, *pA);
printf("value of pointer pB = %d and it points to %d ", pB, *pB);
printf("value of pointer p = %d and it points to %d ", p, *p);
printf("Value of a = %d and &a = %d ", a, &a);
printf("Value of b = %d and &a = %d ", b, &b);

//12
int z[10];
for(int i=0;i<10;i++)
z[i] = i;

//13
for(int i=0;i<10;i++)
printf("address of a[%d] = %d ", i, &z[i]);

//14
for(int i=0;i<10;i++)
printf("Value of (z+%d) = %d ", i, *(z+i));

//15
(*(z+3))++; //it increases value of z[3] by 1 post
printf("Value of *(z+3) = %d ", *(z+3)); //See!! it changed

//16
int *t = z;

//17
for(int i=0;i<4;i++)
printf("*(t+%d) = %d ",i, *(t+i));

t = t+5;
printf("t = %d, *t = %d ", t, *t);
return 1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote