I have the following program:
#include<stdio.h>
int main()
{
int i =257;
int *iptr =&i;
printf("%d%d",*((char*)iptr),*((char*)iptr+1));
return 0;
}
The output is:
1 1
I am not able to understand why the second value is 1.
Please explain.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because 257 in binary is
00000001 00000001: So both the first and the second bytes representing it are set to 1.(char*)iptris thechar(thus 1 byte) pointed byiptr, and(char*)iptr+1is the next byte.