0
Why answer is 64 , can anyone help me
int main() { int a=320; char *ptr; ptr=(char*)&a; printf ("%d",*ptr); }
1 Answer
+ 5
320 in decimal equals to 101000000 in binary (it needs 9 bits to fit in) however a char is 8 bits.
casting a char from an int gives the lowest byte (least significant 8 bits) which in this case is 01000000 and that's 64 in decimal.
the code without using pointers can be written as:
printf("%d", (char)320);
or
int a = 320;
printf("%d", (char)a);