What is the difference between these two code samples? When I print the variable p
, it prints the assigned value like below.
int *p;
p = 51;
printf("%d",p);
Output: 51
When I try to assign p=15
, am I making memory address "15" in the ram as a pointee to the pointer p
? When I try to add int c = 5 +p;
it gives output as 71
. Why am I getting 71?
I thought that the memory address "15" could store any information of the OS, programs, etc. But it exactly stores int
for precise. Though I change the value p = 150;
it gives int
. How is that possible? What's happening under the hood?! I really don't understand.