Initialize Print Following Union Variables 7 70 Using Following Program Union Member Track Q43907250
Initialize and print the following union variables: 7, and 7.0using the following program that has a union and a member to trackwhat’s in the union inside a structure.
#include <stdio.h>
#include <stdlib.h>
/* code for types in union */
#define FLOAT_TYPE 1
#define CHAR_TYPE 2
#define INT_TYPE 3
struct S{
int type_in_union;
union{
floatun_float;
charun_char;
intun_int;
}U;
}S;
void print_vt(void){
switch(S.type_in_union){
default:
printf(“Unknowntype in unionn”);
break;
caseFLOAT_TYPE:
printf(“%fn”,S.U.un_float);
break;
caseCHAR_TYPE:
printf(“%cn”,S.U.un_char);
break;
caseINT_TYPE:
printf(“%dn”,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
return0;
}
Please solve the problem by writing in programming C languageand use the existing code to solve the problem. Please explain whatwe are doing.
Expert Answer
Answer to Initialize and print the following union variables: 7, and 7.0 using the following program that has a union and a member…
OR