int main(void) {
char x;
int y=1280;
x=y;
printf("%d", x);
}
OUTPUT: 0
I remember that int = 4 byte and char is merely 1 byte. So we’re trying to squeeze a 4 byte data into a 1 byte space, but why is the output 0?
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.
Integer types are the most confusing in C/C++ compilers. In your case the answer is simple though, the code demonstares overflow. Char is an 8-bit data type which can only have values 0-255 and 256 which requires 9bits to represent will overflow to 0. Here 1280 = 256*5 and the least significant 8-bits are zero , hence when assigned to a char the value is 0. It will be interesting to see what the output is in MSB vs LSB systems.