Write a C program that reads in a float constant (use %f in scanf) and displays its internal representation in hex. Use your program to check your answers to problem 1. Hint: a union is like a struct except that the fields overlap. Hint: the conversion code for hex is %x. union X { int a; float b; }; int main() { union X test; ... ; test.a and test.b refer to same word in memory but have ; different types.. ... return 0; }
#include <stdio.h>
union X
{
int a;
float b;
};
int main(void) {
union X test;
printf("Enter a value : ");
scanf("%f",&test.b);
printf("Hex value : 0x%x",*(unsigned int*)&test.b);
return 0;
}
//end of program
Output:
Get Answers For Free
Most questions answered within 1 hours.