I am understanding the working of pointers in C. Pointers basically stores the address of the memory (say addr1)
and de-referencing the pointers gives us the value stored at that memory address addr1
. Is there any possible way by which we can directly de-reference the memory address addr1
to get the value stored at that location?
I know how to use a pointer. I just want to know what actually happens behind. I tried to create the same scenario of how the pointer works in the below code using memory address. Although I am stuck in getting the value from a pointer. With this example, I want to know how the de-referencing of a pointer works.
For example:
#define LOCATION 0x68feac //Assuming that the memory location is available
int main()
{
int a = 10;
*(int *)LOCATION = (int)&a;
printf("%x\n", (*(int*)(LOCATION))); //It gives me the address of a
printf("%x\n", *((*(int*)(LOCATION)))); /* I thought it would de-refer but
it gives me compile time error
"invalid type argument of unary
'*'" */
}
I tried using
How to de-reference LOCATION
so that we can get value 10
? Any ideas or suggestions would help.