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: 3684008 • Letter: C

Question

Create a program pointer Tester.c to experiment with pointers. Implement the following steps: Declare three integer variables a, b and c. Initialize them to 0,100 and 225 Print the value of each variable and its address. Add the following declaration to your code: int *pA = &a.; *pB - &b;, *p; Print the value of each pointer and the value it points to What is the value of (*p)? Print the value of each pointer and the value it points to using the ~%p" specifier. Run your program multiple times Does any of the values *pA. *pB or *p change? Does the values pA, pB or p change? Change the value that p points to to 50. Set p to point to a; Find 3 different ways to change the value of a to 92; Add the following to your code: What is the effect of the previous statements? Verify by printing the values of p. pA, pB.' *pA. *pB. a. b. &a.; &b; after every step. 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 Print the values of z. (z + 1), (z + 2).(z + 12). Add the following: *{z + 3|++. What does this statement do? Add the following: int * t = z; Print t, t + 1, t + 2, t + 3, t + 4. Set t to t + S. Print t. *t.

Explanation / Answer

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

2) printf("%d %p ",a,&a);
   printf("%d %p ",b,&b);
   printf("%d %p ",c,&c);

0 0xbf91c234
100 0xbf91c238
225 0xbf91c23c

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

4) printf("%p %d ",pA,*pA);
   printf("%p %d ",pB,*pB);
printf("%p %d ",p,*p);

0xbf91c234 0
0xbf91c238 100

As p is no initialized the last printf statement throws an error.

5) printf("%p %d ",pA,*pA);
   printf("%p %d ",pB,*pB);
printf("%p %d ",p,*p);

0xbf91c234 0
0xbf91c238 100

6) The values of pA,pB,p change in every different run. The values of *pA,*pB does not change. The value *p cannot be accesed as p is not initialized. So I'm running the program by not printing *p.

7) *p=50

8) p = &a;

9) a=92

*p=92

*(&a)=92

10) p=pA;

*p=22;

p=pB;

*p=18;

p=&b;

*p=108;

p=pA;

*p=2;

*p=&a;

11) 0xbf91c234 0xbf91c238 0 100 0 100 0xbf91c234 0xbf91c238
0xbf91c234 0xbf91c238 22 100 22 100 0xbf91c234 0xbf91c238
0xbf91c234 0xbf91c238 22 100 22 100 0xbf91c234 0xbf91c238
0xbf91c234 0xbf91c238 22 18 22 18 0xbf91c234 0xbf91c238
0xbf91c234 0xbf91c238 22 18 22 18 0xbf91c234 0xbf91c238
0xbf91c234 0xbf91c238 22 108 22 108 0xbf91c234 0xbf91c238
0xbf91c234 0xbf91c238 22 108 22 108 0xbf91c234 0xbf91c238
0xbf91c234 0xbf91c238 2 108 2 108 0xbf91c234 0xbf91c238
0xbf91c234 0xbf91c238 -1080966604 108 -1080966604 108 0xbf91c234 0xbf91c238

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

13) 0xbfde25f8
0xbfde25fc
0xbfde2600
0xbfde2604
0xbfde2608
0xbfde260c
0xbfde2610
0xbfde2614
0xbfde2618
0xbfde261c

14) 0xbfde25f8
0xbfde25fc
0xbfde2600
0xbfde2604
0xbfde2608
0xbfde260c
0xbfde2610
0xbfde2614
0xbfde2618
0xbfde261c

15) *(z+3)++, increments the value of z+3 which is invalid. It is equivalent to *((z+3)++).

(*(z+3))++ increments z[3] to 4.

16) int *t=z;

17) 0xbf88cf18
0xbf88cf1c
0xbf88cf20
0xbf88cf24
0xbf88cf28

18) As expected this gives out the value of t,t[5] which is same as z,z[5].

Complete program:

#include <stdio.h>

int main(void) {
   // your code goes here
int a=0,b=100,c=225;
   printf("%d %p ",a,&a);
   printf("%d %p ",b,&b);
   printf("%d %p ",c,&c);
  
   int *pA=&a,*pB=&b,*p;
   printf("%p %d ",pA,*pA);
   printf("%p %d ",pB,*pB);
   printf("%p %d ",p,10);
   p=pA;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
*p=22;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
p=pB;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
*p=18;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
p=&b;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
*p=108;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
p=pA;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
*p=2;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
*p=&a;
printf("%p %p %d %d %d %d %p %p ",pA,pB,*pA,*pB,a,b,&a,&b);
int z[10];
int i;
for(i=0;i<10;i++)
z[i]=i;
for(i=0;i<10;i++)
printf("%p ",&z[i]);
printf("**** ");
for(i=0;i<10;i++)
printf("%p ",z+i);
(*(z+3))++;
printf("%d ",z[3]);
printf("**** ");
int *t=z;
for(i=0;i<5;i++)
printf("%p ",t+i);
t=t+5;
printf("%p %d ",t,*t);

   return 0;
}

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