Unions
- What type of data is holded by variable u int in the following C code?
#include <stdio.h>
union Example
{
int Nval;
float Fval;
char *Sval;
} e;
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Will be large enough to hold the largest of the three types;
- What will be the output of the following C code (Assuming size of int and float is 4)?
#include <stdio.h>
union
{
int Nval;
float Fval;
} U;
void main()
{
printf("%d", sizeof(U));
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
4
- In the following C code, we can access the 1st character of the string sval by using _______.
#include <stdio.h>
struct
{
char *Name;
union
{
char *Str;
} u;
} tab[15];
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Both tab[i].u.Str[0]. & *tab[i].u.Str
- Members of a union are accessed as________________.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
both union-pointer->member & union-name.member
- Which member of the union will be active after REF LINE in the following C code?
#include <stdio.h>
union test
{
int n;
float fl;
char ch;
};
union test t = {11,12.25,’N’}; //REF LINE
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
n