C-Structure & Union Question and Answer
C-Structure & Union Question and Answer
81. Find the output
union unit
{
int x;
char y;
};
union neon
{
union unit u;
char ch;
};
void main ( )
{
union neon n={50};
printf("%d %c %c", n.u.x, n.ch, n.u.y);
}
union unit
{
int x;
char y;
};
union neon
{
union unit u;
char ch;
};
void main ( )
{
union neon n={50};
printf("%d %c %c", n.u.x, n.ch, n.u.y);
}
- 50 2 2
- 50 garbage garbage
- 50 50 50
- 50 2 garbage
82. Find the output
union uuu
{
struct student
{
int roll;
char name [10];
float percentage;
};
float sal;
};
void main ( )
{
union uuu u;
printf('%d", sizeof (u));
}
union uuu
{
struct student
{
int roll;
char name [10];
float percentage;
};
float sal;
};
void main ( )
{
union uuu u;
printf('%d", sizeof (u));
}
- 4
- 10
- 16
- Error, too many types in declaration
83. State the correct statement
- Union declaration reservesd memory but definition doesn't.
- Structure declaration reserves memory but definition doesn't
- Data members of structure are private by default.
- None of the above
84. Find the output
union un
{
int x;
char y;
float z;
};
void main ( )
{
union un *u;
u=(union un*) malloc (sizeof(union un));
u->x=10;
u->'a'
printf("%d", u->x);
}
union un
{
int x;
char y;
float z;
};
void main ( )
{
union un *u;
u=(union un*) malloc (sizeof(union un));
u->x=10;
u->'a'
printf("%d", u->x);
}
- 10
- 97
- Garbage output
- Compilation error
85. Which is not possible with union ?
- Array of union
- Pointer to union
- Self-referential union
- None of the above
86. Find the output
#define MAX int a
union uuu
{
MAX;
float b;
};
void main ( )
{
union uuu u={5.5};
printf('%d", u.a);
}
#define MAX int a
union uuu
{
MAX;
float b;
};
void main ( )
{
union uuu u={5.5};
printf('%d", u.a);
}
- 5.0
- 5
- Compilation error
87. Which of the following is used to increment the pointer "p" to next member of the array?
union choice
{
int x[10];
float f[10];
};
union choice colour[15];
void *p=colour;
union choice
{
int x[10];
float f[10];
};
union choice colour[15];
void *p=colour;
- p=p+sizeof(choice.x);
- p=p+sizeof)*p);
- p=(void*)((union choice *) p+a);
- p=(void*)(union choice *)p;
88. Find the output
union xyz
{
char name [10];
char x;
};
void main ( )
{
union xyzp={"raja")};
p.x='i\r';
p.x='ij';
printf("%s", p.name);
}
union xyz
{
char name [10];
char x;
};
void main ( )
{
union xyzp={"raja")};
p.x='i\r';
p.x='ij';
printf("%s", p.name);
}
- iija
- iaja
- jaja
- None of these
89. Find the output
union abc
{
int ;
float f;
}ab;
void main ( )
{
ab.i=23.567;
printf('%f", ab.f);
}
union abc
{
int ;
float f;
}ab;
void main ( )
{
ab.i=23.567;
printf('%f", ab.f);
}
- 23.567
- 23.0000
- suffering
- None of these
90. Find the output
union uni
{
int x;
char: 8;
};
void main ( )
{
union uni u={64};
printf("%c");
}
union uni
{
int x;
char: 8;
};
void main ( )
{
union uni u={64};
printf("%c");
}
- A
- Garbage
- Declaration terminated incorrectly
- None of these