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 21:30
The graph shows median weekly earnings for full-time workers according to education level. which can you not conclude?
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
Norder to receive financial aid at his vocational school, mario must fill out the fafsa. the fafsa is a form that must be completed to determine . in order to complete a fafsa, you must submit . the fafsa can students obtain
Answers: 2
question
Computers and Technology, 23.06.2019 22:20
Read “suburban homes construction project” at the end of chapters 8 and 9 (in the textbook) and then develop a wbs (work breakdown structure) in microsoft excel or in microsoft word (using tables)
Answers: 1
question
Computers and Technology, 24.06.2019 16:30
What is the item which could be matched with a statement below? software installed on a computer that produces pop-up ads using your browser an example of social engineering malware loads itself before the os boot is complete type of spyware that tracks your keystrokes, including passwords windows key + l the practice of tricking people into giving out private information or allowing unsafe programs into the network or computer when someone who is unauthorized follows the employee through a secured entrance to a room or building a type of malware that tricks you into opening it by substituting itself for a legitimate program a computer that has been hacked, and the hacker is using the computer to run repetitive software in the background without the user's knowledge an infestation designed to copy itself repeatedly to memory, on drive space, or on a network
Answers: 1
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
Mathematics, 30.07.2019 02:30
Questions on the website: 13722360