Discussion
Which of the statements is correct about the program?
#include <stdio.h>
int main()
{
float a=3.14;
char *j;
j = (char*)&a;
printf("%d\n", *j);
return 0;
}
Answer: A
Correct answer: It prints ASCII value of the binary number present in the first byte of a float variable a.
Casting &a to char * reinterprets the float's storage as bytes. Dereferencing reads the first byte of the IEEE representation of 3.14 - a piece of the mantissa, not the number 3 - and %d prints that byte's numeric value.
The output is therefore a small integer determined by the bit pattern and by the machine's endianness, with no arithmetic relationship to 3.14. The other options misdescribe it: %d prints a number rather than a character, and the value is deterministic rather than garbage.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development