I'm trying to understand how pointers work. I created an int
value and made a char
pointer to point at it.
When printing the content of the address that char
pointer points to, I don't get the expected result.
Like if that char
pointer is pointing to 256, I was expecting the content of that address to return 0 because (256)10 = (0000000100000000)2. Because a char
pointer points to one byte so it'll return the first 8 bits which are zeros.
But it returns -1.
Here's my code
#include <stdio.h>
int main()
{
int y = 256;
char *p = (char *)&y;
// returns Value -1
printf("Value %d \n", *p);
return 0;
}