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 11:30
Andrina writes letters that are regularly sent to hundreds of her company’s customers. because of this, she would like for the mail merge command to be in her quick access toolbar, and she wants it to be the first button on the left. what should andrina do to place the mail merge button there?
Answers: 1
question
Computers and Technology, 22.06.2019 21:00
The average cost of one year at a private college in 2012-2013 is $43,289. the average grant aid received by a student at a private college in 2012-2013 is $15,680.   what is the average student contribution for one year at a private college in 2012-2013?
Answers: 3
question
Computers and Technology, 23.06.2019 23:30
Match the following errors with their definitions. a. #name b. #value c. #ref d. 1. when a formula produces output that is too lengthy to fit in the spreadsheet cell 2. when you enter an invalid cell reference in a formula 3. when you type text in cells that accept numeric data 4. when you type in a cell reference that doesn’t exist
Answers: 1
question
Computers and Technology, 24.06.2019 12:00
What is a sketch or blueprint of a web page that shows the structure (but not the detailed design) of basic page elements such as the logo, navigation, content, and footer?
Answers: 3
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