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
One subtask in the game is to roll the dice. explain why is roll the dice an abstraction.
Answers: 3
question
Computers and Technology, 22.06.2019 22:00
Researchers measured the data speeds for a particular smartphone carrier at 50 airports. the highest speed measured was 78.1 mbps. the complete list of 50 data speeds has a mean of x overbarequals16.11 mbps and a standard deviation of sequals18.65 mbps. a. what is the difference between carrier's highest data speed and the mean of all 50 data speeds? b. how many standard deviations is that [the difference found in part (a)]? c. convert the carrier's highest data speed to a z score. d. if we consider data speeds that convert to z scores between minus2 and 2 to be neither significantly low nor significantly high, is the carrier's highest data speed significant? a. the difference is nothing mbps.
Answers: 3
question
Computers and Technology, 22.06.2019 23:30
Which of the following is not a symptom of chronic fatigue syndrome
Answers: 2
question
Computers and Technology, 23.06.2019 04:00
Laire writes a letter to her grandmother, in which she describes an amusement park she visited last week. she adds pictures of that place in her letter. which feature of a word processing program will claire to remove unwanted parts of the pictures?
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
question
Social Studies, 05.01.2021 02:20
question
Mathematics, 05.01.2021 02:20
question
Mathematics, 05.01.2021 02:20
question
Mathematics, 05.01.2021 02:30
question
Mathematics, 05.01.2021 02:30
Questions on the website: 13722362