C-Structure & Union Question and Answer
C-Structure & Union Question and Answer
71. Find the output
union india
{
int i;
char ch[2];
}
orissa;
void main ( )
{
orissa.ch[0]=1;
orissa.ch[1]=2;
printf("%d", orissa.i);
}
union india
{
int i;
char ch[2];
}
orissa;
void main ( )
{
orissa.ch[0]=1;
orissa.ch[1]=2;
printf("%d", orissa.i);
}
- 513
- 257
- 21
- 12
72. Find the output
union abc
{
int x;
char c;
struct str
{
int a;
char b;
char c;
}p;
}q;
void main ( )
{
printf('%d", sizeof(q));
}
union abc
{
int x;
char c;
struct str
{
int a;
char b;
char c;
}p;
}q;
void main ( )
{
printf('%d", sizeof(q));
}
- 2
- 4
- 7
- Compiltion error
73. Find the output
union xxx
{
int x;
float y;
}xx;
void func(union xxx x);
void main ( )
{
xx.x=10;
xx.y=3.14;
func(xx);
printf("%d", xx.x);
}
void func (union xxx xx
{
xx.x=20;
printf("%d", xx.x);
return;
}
union xxx
{
int x;
float y;
}xx;
void func(union xxx x);
void main ( )
{
xx.x=10;
xx.y=3.14;
func(xx);
printf("%d", xx.x);
}
void func (union xxx xx
{
xx.x=20;
printf("%d", xx.x);
return;
}
- Garbage Garbage
- 20 Garbage
- Garbage 20
- Compilation error
74. Find the output
union sbi
{
int i;
char ch[2];
};
void main ( )
{
union sbi idco={127};
printf('%d %d%d", idco.i,
idco.ch[0], idco.ch[1]);
}
union sbi
{
int i;
char ch[2];
};
void main ( )
{
union sbi idco={127};
printf('%d %d%d", idco.i,
idco.ch[0], idco.ch[1]);
}
- 127 127 0
- 127 127 127
- 127 Garbage Garbage
- 127 127 Garbage
75. Find the output.
union uni
{
int x;
char y;
};
void main ( )
{
union uni u;
u.x =90;
printf("%c", u.y);
}
union uni
{
int x;
char y;
};
void main ( )
{
union uni u;
u.x =90;
printf("%c", u.y);
}
- 9
- Z
- Compilation error
- None of these
76. Find the output
union res
{
char a:6;
int b:8;
};
void main ( )
{
union res s;
pintf("%d", sizeof (s));
}
union res
{
char a:6;
int b:8;
};
void main ( )
{
union res s;
pintf("%d", sizeof (s));
}
- 14
- 8
- 1
- 2
77. Find the output.
union res
{
int a:16;
char b:10;
};
void main ( )
{
union res s;
s.b='B';
s.a=10;
printf('%c%d", s.b, s.a);
}
union res
{
int a:16;
char b:10;
};
void main ( )
{
union res s;
s.b='B';
s.a=10;
printf('%c%d", s.b, s.a);
}
- 2048 10
- B 2144
- B 10
- Compilation error
78. Find the output
union uni
int x;
int a:8;
char b:8;
};
void main ( )
{
union uni u={48};
printf('%d %d", u.a, u.b);
}
union uni
int x;
int a:8;
char b:8;
};
void main ( )
{
union uni u={48};
printf('%d %d", u.a, u.b);
}
- Invalid initialization
- 48 0
- 48 48
- 0 0
79. Find out the true statement.
- A union variable can be assigned to another union variable.
- The address of union variable can be extracted by using & operator.
- A function can return a pointer to the union
- All of the above
80. Which member of a union is in use at any time can be known explicitly using
- Enum
- Bit fields
- Static members
- Can't be determined