In: Computer Science
THE FOLLOWING MUST BE CODED IN C THE FOLLOWING MUST BE CODED IN C
THE FOLLOWING MUST BE CODED IN C THE FOLLOWING MUST BE CODED IN C
Write a program that demonstrates handling pointers. Create two integer variables m and n, and two pointers, pm pointing to m, and pn pointing to n.
Produce the following output:
Address of m: 0x7ffcc3ad291c
Value of m: 29
Address of n: 0x7ffcc3ad291d
Value of n: 34
Now pm is pointed to m by assigning the address of m to pm
Address of pointer pm: 0x7ffcc3ad2100
Value of pointer pm: 0x7ffcc3ad291c
Content of pointer pm (dereferencing): 29
Now pn is pointed to n by assigning the address of n to pn
Address of pointer pn: 0x7ffcc3ad2101
Value of pointer pn: 0x7ffcc3ad291d
Content of pointer pn (dereferencing): 34
Thank you!
#include <stdio.h>
int main()
{
int m=29,n=34;
int* pm, *pn;
printf("Address of m: %p\n", &m);
printf("Value of m: %d\n", m);
printf("Address of n: %p\n", &n);
printf("Value of n: %d\n", n);
pm=&m;
pn=&n;
printf("Address of pointer pm: %p\n", &pm);
printf("Value of pointer pm: %p\n", pm);
printf("Content of pointer pm(dereferencing): %d\n",*pm);
printf("Address of pointer pn: %p\n", &pn);
printf("Value of pointer pn: %p\n", pn);
printf("Content of pointer pn(dereferencing): %d\n",*pn);
return 0;
}