#include <stdio.h>
int main()
{
float a = 12.5;
printf("%d\n", a);
printf("%d\n", *(int *)&a);
return 0;
}
Additionally, how do you interpret the expression *(int *)&a?
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.
It takes the address of a float, casts it to an integer pointer and then dereferences that as an integer. Totally wrong.
There are at least two things wrong here:
So the output to the second printf (if it doesn’t happen to crash since it’s undefined behavior, as per the first point) would likely be some strange, huge number.