Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

Output required:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

More Books

Students also viewed these Databases questions