It is a question given in one of our placement Exams. explain the output of the following code...
#include <stdio.h>
int main(void)
{
int i = 320;
char *ptr = (char *)&i;
printf("%d", *ptr);
return 0;
}
It is a question given in one of our placement Exams. explain the output of the following code...
#include <stdio.h>
int main(void)
{
int i = 320;
char *ptr = (char *)&i;
printf("%d", *ptr);
return 0;
}
You will get the numeric value of the "first" byte that makes up the int
with value 320.
The precise output depends on the endianness of your platform:
64
0
Here are the octet-components of a 32-bit int
on a little-endian, two's-complement system:
0x40
0x01
0x00
0x00
(An octet is an 8-bit byte. Your platform probably has octets as char
, however more exotic platforms, with larger CHAR_BIT
values, do exist.)