WorksheetsStructures and union
Total questions: 15
Worksheet time: 20mins
Which among the following is never possible in C when members in a structure are same as that in a union?
//Let P be a structure
//Let Q be a union
a.sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is equal to sizeof(Q)
c. sizeof(P) is less than to sizeof(Q)
d. None of the above
Which of the following are themselves a collection of different data types?
String
Structure
Integer
None of these
Which of the following cannot be a structure member?
Another structure
Array
Function
None of these
What is the output of this C code?
#include <stdio.h>
struct student
{
int no; char name[20];
};
void main()
{ student s;
s.no = 8;
printf("hello");
}
Hello
Nothing
Compilation error
Which of the following share a similarity in syntax?
1. Union, 2. Structure, 3. Arrays and 4. Pointers
1 & 2
3&4
1&3
2&3
For what minimum value of x in a 32-bit Linux OS would make the size of s equal to 8 bytes?struct temp
{
int a : 13;
int b : 8;
int c : x;
}s;
4
8
12
16
Which operator connects the structure name to its member name?
-
.
=>
@
What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
struct student s;
struct student fun(void)
{
s.name = "newton";
printf("%s\n", s.name);
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s\n", m.name);
m.name = "turing";
printf("%s\n", s.name);
}
Alan alan newton
Newton alan alan
Alan newton alan
Compile time error
What will be the output of the below coding #include <stdio.h>
struct temp
{
int a;
} s;
void func(struct temp s)
{
s.a = 10;
printf("%d\t", s.a);
}
main()
{
func(s);
printf("%d\t", s.a);
}
10,garbage value
Garbage value,10
0,10
10,0
Size of the following union (assume size of int=2, size of float=4 and size of char=1);
union ABC
{
int a;
float b;
char c;
};
2
4
1
8
What is wrong with the following code?
struct Person{ char name; struct Person *Mother, *Father; }Anita;
The ; should appear after the } and Anita be defined later
name should be defined as an array
There is no error in the code
struct Person Mother, Father; must be defined as struct Person Mother, Father;
What will be the output of the following code?
struct { int a;
double d;
float cp;
}s;
void main()
{
printf("%d\t%d\t%d\t%d", sizeof(s.a), sizeof(s.d), sizeof(s.cp), sizeof(s));
}
4,8,4,24
4,4,8,8
4,8,24,8
4,4,4,28
What is important difference between structure & union?
There is no difference
Union takes less memory then structure
Union woks faster then structure
Structure takes less memory then union
Is it necessary that all elements of structure should be different
Yes
No
Which of the following accesses a variable in structure b?
b->var
b.var
b*var
b-var
