Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Initialize and print the following union variables: 7, and 7.0 using the following program that has a union and a member to track what's in

Initialize and print the following union variables: 7, and 7.0 using the following program that has a union and a member to track what's in the union inside a structure.

#include

#include

/* code for types in union */

#define FLOAT_TYPE 1

#define CHAR_TYPE 2

#define INT_TYPE 3

struct S{

int type_in_union;

union{

float un_float;

char un_char;

int un_int;

}U;

}S;

void print_vt(void){

switch(S.type_in_union){

default:

printf("Unknown type in union ");

break;

case FLOAT_TYPE:

printf("%f ", S.U.un_float);

break;

case CHAR_TYPE:

printf("%c ", S.U.un_char);

break;

case INT_TYPE:

printf("%d ", S.U.un_int);

break;

}

}

int main(){

S.type_in_union = FLOAT_TYPE;

S.U.un_float = 3.5;

print_vt();

S.type_in_union = CHAR_TYPE;

S.U.un_char = 'a';

print_vt();

// Your Code

return 0;

}

Please solve the problem by writing in programming C language and use the existing code to solve the problem. Please explain what we are doing.

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

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions

Question

What is the role of the audit committee of the board of directors?

Answered: 1 week ago

Question

2. What are the different types of networks?

Answered: 1 week ago