Question: Output required: This is my code at the moment #include union number { char a; short b; int c; long d; }; int main (void)

 Output required: This is my code at the moment #include union

Output required:

number { char a; short b; int c; long d; }; int

This is my code at the moment

#include

union number { char a; short b; int c; long d;

};

int main (void) {

union number u;

printf("Enter a character: "); scanf("%c", &(u.a)); printf("Printed as a character is %c ", u.a); printf("Printed as a short integer: %hi ", u.b); printf("Printed as an integer: %d ", u.c); printf("Printed as a long integer: %ld ", u.d);

printf("Enter a short integer: "); scanf("%hi", &(u.b)); printf("Printed as a character is %c ", u.a); printf("Printed as a short integer: %hi ", u.b); printf("Printed as an integer: %d ", u.c); printf("Printed as a long integer: %ld ", u.d);

printf("Enter an integer: "); scanf("%d", &(u.c)); printf("Printed as a character is %c ", u.a); printf("Printed as a short integer: %hi ", u.b); printf("Printed as an integer: %d ", u.c); printf("Printed as a long integer: %ld ", u.d);

printf("Enter a long integer: "); scanf("%ld", &(u.d)); printf("Printed as a character is %c ", u.a); printf("Printed as a short integer: %hi ", u.b); printf("Printed as an integer: %d ", u.c); printf("Printed as a long integer: %ld ", u.d);

return 0; }

My output does not match and I need help.

10.8 Create union integer with members charc, short s, int i and long b. Write a program that inputs value of type char, short, int and long and stores the values in union variables of type union integer. Each union variable should be printed as a char, a short, an int and a long. Do the values always print correctly? Enter a character: A 'A' printed as a character is A 'A' printed as a short integer is -13247 'A' printed as an integer is -858993599 'A' printed as a long integer is -858993599 Enter a short integer: 97 97 printed as a character is a 97 printed as a short integer is 97 97 printed as an integer is -859045791 97 printed as a long integer is -859045791 Enter an integer: 32700 32700 printed as a character is + 32700 printed as a short integer is 32700 32700 printed as an integer is 32700 32700 printed as a long integer is 32700 Enter a long integer: 10000000 10000000 printed as a character is 10000000 printed as a short integer is -27008 10000000 printed as an integer is 10000000 10000000 printed as a long integer is 10000000

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!