subject
Computers and Technology, 11.03.2022 17:30 gbjjh

Create union integer with members char c, short s, int i and long b. Write a program that inputs values 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? #include
//Union integer definition
union integer
{
char c;
short s;int i;
long b;
};
//Main function
int main(void)
{
// define union a
union integer a;
// prompt user to enter character from input device
printf("Enter a character: ");

// read character and put in union
scanf("%c", &a. c);
//Print the values of union
printf("%c printed as a character: %c\n", a. c, a. c);
printf("%c printed as a short: %hd\n", a. c, a. s);
printf("%c printed as an integer: %d\n", a. c, a. i);
printf("%c printed as a long: %ld\n", a. c, a. b);
//prompt user to enter a short value
printf("\nEnter a short: ");
// read short and put in union
scanf("%hd", &a. s);
//Print eh values of union
printf("%c printed as a character: %c\n", a. s, a. c);
printf("%c printed as a short: %hd\n", a. s, a. s);
printf("%c printed as an integer: %d\n", a. s, a. i);
printf("%c printed as a long: %ld\n", a. s, a. b);
//prompt user to enter an integer value
printf("\nEnter an integer: ");
// read integer and put in union
scanf("%d", &a. i);
//Print eh values of union
printf("%c printed as a character: %c\n", a. i, a. c);
printf("%c printed as a short: %hd\n", a. i, a. s);
printf("%c printed as an integer: %d\n", a. i, a. i);
printf("%c printed as a long: %ld\n", a. i, a. b);
//prompt user to enter an long value
printf("\nEnter a long: ");
// read long and put in union
scanf("%ld", &a. b);
//Print eh values of union
printf("%c printed as a character: %c\n", a. b, a. c);
printf("%c printed as a short: %hd\n", a. b, a. s);
printf("%c printed as an integer: %d\n", a. b, a. i);
printf("%c printed as a long: %ld\n", a. b, a. b);
return 0;
}// end main

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:30
Select all that apply. which of the following are proofreading options included in microsoft word? spell check find replace grammar check formatting check
Answers: 1
question
Computers and Technology, 23.06.2019 02:30
Experimental data that is expressed using numbers is said to be
Answers: 1
question
Computers and Technology, 23.06.2019 05:00
In cell b18, enter a formula to calculate the amount budgeted for meals. this amount is based on the daily meal allowance and the total travel days (# of nights+1).
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Which company provides a crowdsourcing platform for corporate research and development? a: mtruk b: wiki answers c: mediawiki d: innocentive
Answers: 2
You know the right answer?
Create union integer with members char c, short s, int i and long b. Write a program that inputs val...
Questions
question
English, 08.10.2019 15:30
question
Chemistry, 08.10.2019 15:30
question
Mathematics, 08.10.2019 15:30
question
Social Studies, 08.10.2019 15:30
Questions on the website: 13722360