pointers

can smbdy plz explain the output.

1
2
3
4
5
6
7
8
#include <stdio.h>

int main()
{
    int i=320;
    char *ptr=(char*)&i;
    printf("%d",*ptr);
}
Last edited on
char data type is only 1 byte large.
The int 320 is stored as a bunch of zeroes, ending with ...0 0001 0100 0000(spaces for clarity).
101000000 in binary is 320 in decimal.

1 byte is 8 bits (most likely for you), so it only saves the "0100 0000" part of the int.
0100 0000 in decimal is 64, and this is what it prints (at least on my computer).
Last edited on
Topic archived. No new replies allowed.