About [num]
value of [num] = 10
memory location of [num] = 0115FC14
About [numPtr1]
value of [numPtr1] when it dereferenced = 10
address of [numPtr1] is holding = 0115FC14
memory location of [numPtr1] = 0115FC08
About [numPtr2]
value of [numPtr2] when it dereferenced once = 0115FC14(*numPtr2)
value of [numPtr2] when it dereferenced twice = 10(**numPtr2)
address of [numPtr2] holding = 0115FC08(numPtr2) is equals to memory location of [numPtr1] = 0115FC08(&numPtr1)
memory location of [numPtr2] = 0115FBFC
Name |
num |
numPtr1 |
numPtr2
|
Value |
10 |
0115FC14 |
0115FC08
|
Memory location |
0115FC14 |
0115FC08 |
0115FBFC
|
Here is the code
#include <stdio.h>
int main(void)
{
int a = 5;
int* a_ptr1 = &a;
int** a_ptr2 = &a_ptr1;
puts("***About [a]***");
printf("value of [a] = %d\nmemory location of [a] = %p\n\n", a, &a);
puts("***About [a_ptr1]***");
printf("value of [a_ptr1] when it dereferenced = %d\n", *a_ptr1);
printf("address of [a_ptr1] is holding = %p\n", a_ptr1);
printf("memory location of [a_ptr1] = %p\n\n", &a_ptr1);
puts("***About [a_ptr2]***");
printf("value of [a_ptr2] when it dereferenced once = %p(*a_ptr2)\n", *a_ptr2);
printf("value of [a_ptr2] when it dereferenced twice = %d(**a_ptr2)\n", **a_ptr2);
printf("address of [a_ptr2] holding = %p(a_ptr2) ", a_ptr2);
printf("is equals to memory location of [a_ptr1] = %p(&a_ptr1)\n", &a_ptr1);
printf("memory location of [a_ptr2] = %p\n\n", &a_ptr2);
printf("Name\t\t[a]<---------[a_ptr1]<-------[a_ptr2]\n");
printf("Value\t\t%d %p %p\n", a, a_ptr1, a_ptr2);
printf("Address\t\t%p %p %p\n", &a, &a_ptr1, &a_ptr2);
}