Explore topic-wise MCQs in Structures, Unions, Enums.

This section includes 83 Mcqs, each offering curated multiple-choice questions to sharpen your Structures, Unions, Enums knowledge and support exam preparation. Choose a topic below to get started.

1.

What will be the output of the program if it is executed like below?
cmd> sample

 /* sample.c */ #include int main(int argc, char **argv) { printf("%s n", argv[argc-1]); return 0; }

A. sample
B. samp
C. No output
Answer» C. No output
2.

Find the output of below C program

 #include "stdio.h" typedef enum{ Male, Female }SEX; int main() { SEX var = Male; printf("%d",var); return 0; }

A. Male
B. 1
C. Compilation Error
Answer» A. Male
3.

What is the output of this C code?

 #include  struct student { int no; char name[20]; } void main() { struct student s; s.no = 8; printf("hello"); }

A. Compile time error
B. Nothing
C. hello
D. Varies
Answer» B. Nothing
4.

Which of the following structure declaration will throw an error?

A. struct temp{}s; main(){}
B. struct temp{}; struct temp s; main(){}
C. struct temp s; struct temp{}; main(){}
D. None of the mentioned
Answer» E.
5.

String handling functions such as strcmp(), strcpy() etc can be used with enumerated types.

A. TRUE
B. FALSE
C. May Be
D. Can't Say
Answer» C. May Be
6.

If we do not explicitly assign values to enum names, the compiler by default assigns values to ?

A. null
B. -1
C. Garbage
Answer» A. null
7.

All enum constants are?

A. Same in their scope
B. unique in their scope
C. contain dupicate value in their scope
D. None of the above
Answer» C. contain dupicate value in their scope
8.

Enumeration (or enum) is a ______ data type in C?

A. user defined
B. built-in
C. libary
D. None Of the above
Answer» B. built-in
9.

 #include "stdio.h" typedef enum{ Male=5, Female }SEX; int main() { SEX var = Male; SEX var1 = Female; printf("%d %d",var, var1); return 0; }

A. Male Female
B. 0 1
C. 5 5
D. 5 6
Answer» E.
10.

What will be the output of the following C code if input given is 2?

 #include enum day { a,b,c=5,d,e }; main() { printf("Enter the value for a"); scanf("%d",a); printf("%d",a); }

A. 2
B. 3
C. Error
Answer» E.
11.

 #include  typedef enum{ Male=-1, Female }SEX; int main() { SEX var = Male; SEX var1 = Female; printf("%d %d",var, var1); return 0; }

A. -1 0
B. -1 -2
C. -1 -1
D. Compilation Error
Answer» B. -1 -2
12.

Can we have enum containing enum with same contestant?

 #include "stdio.h" enum Yenum{ C, CPP, Java }; enum Xenum{ C, CPP, Java, Yenum }; int main() { enum Xenum var; printf("%d",sizeof(var)); return 0; }

A. Enum can contain enum but duplicate contestants are not allowed
B. Enum can't contain enum
C. Enum can contain enum but not accessible
D. This code will produce compilation error
Answer» B. Enum can't contain enum
13.

Assume that this code is running on 64 bit system

 #include  enum Xenum{ C, CPP, Java }; int main() { enum Xenum var; printf("%d",sizeof(var)); return 0; }

A. 1
B. 3
C. 4
D. 12
Answer» D. 12
14.

What is the correct syntax of enum?

A. enum flag{constant1, constant2, constant3, ....... };
B. enum flag(constant1, constant2, constant3, ....... );
C. enum flag[constant1, constant2, constant3, ....... ];
D. enumflag{constant1, constant2, constant3, ....... };
Answer» B. enum flag(constant1, constant2, constant3, ....... );
15.

What will be output for the following code?

A. error
B. success
C. failure
Answer» B. success
16.

Arithmetic operations are not allowed on enumerated constants.

A. TRUE
B. FALSE
C. May Be
D. Can't Say
Answer» C. May Be
17.

User-defined data type can be derived by___________

A. struct
B. enum
C. typedef
D. all of the mentioned
Answer» E.
18.

 #include >stdio.h> typedef enum{ Male, Female=-1 }SEX; int main() { SEX var = Male; SEX var1 = Female; printf("%d %d",var, var1); return 0; }

A. Compilation Error
B. Garbage Value 0
C. -1 -1
D. 0 -1
Answer» E.
19.

 #include  typedef enum{ Male, Female }SEX; int main() { SEX var = Male; SEX var1 = Female; printf("%s %s",var, var1); return 0; }

A. Male Female
B. 0 1
C. Runtime error (Segmentation fault)
D.
Answer» D.
20.

 #include  typedef enum{ Male, Female=0 }SEX; int main() { SEX var = Male; SEX var1 = Female; printf("%d %d",var, var1); return 0; }

A. 0 0
B. -1 0
C. Some Garbage Value 0
D. Compilation Error
Answer» B. -1 0
21.

The above C declaration define 's' to be

 struct node { int i; float j; }; struct node *s[10];

A. An array, each element of which is a pointer to a structure of type node
B. A structure of 2 fields, each field being a pointer to an array of 10 elements
C. A structure of 3 fields: an integer, a float, and an array of 10 elements
D. An array, each element of which is a structure of type node.
Answer» B. A structure of 2 fields, each field being a pointer to an array of 10 elements
22.

Assume that size of an integer is 32 bit. What is the output of following program?

 #include struct st { int x; static int y; }; int main() { printf("%d", sizeof(struct st)); return 0; }

A. 4
B. 8
C. Compiler Error
D. Runtime Error
Answer» D. Runtime Error
23.

Which of the following cannot be a structure member?

A. Function
B. Array
C. Structure
D. None of the above
Answer» B. Array
24.

Which of the following are themselves a collection of different data types?

A. String
B. Structures
C. Char
D. None of the above
Answer» C. Char
25.

Consider the following declaration :

 struct addr { char city[10]; char street[30]; int pin ; }; struct { char name[30]; int gender; struct addr locate; } person , *kd = &person ;

Then *(kd -> name +2) can be used instead of

A. person.name +2
B. kd -> (name +2 )
C. *((*kd).name + 2 )
D. either (A) or (B), but not (C)
Answer» D. either (A) or (B), but not (C)
26.

Pick the best statement for the below program:

 #include "stdio.h" int main() { union {int i1; int i2;} myVar = {.i2 =100}; printf("%d %d",myVar.i1, myVar.i2); return 0; }

A. Compile error due to incorrect syntax of initialization.
B. No compile error and it ll print 0 100
C. No compile error and it ll print 100 100
Answer» D.
27.

Pick the best statement for the below program:

 #include "stdio.h" int main() { struct {int i; char c;} myVar = {.c ='A',.i = 100}; printf("%d %c",myVar.i, myVar.c); return 0; }

A. Compile error because struct type (containing two fields of dissimilar type i.e. an int and a char) has been mentioned along with definition of myVar of that struct type.
B. Compile error because of incorrect syntax of initialization of myVar. Basically, member of operator (i.e. dot .) has been used without myVar.
C. Compile error for not only B but for incorrect order of fields in myVar i.e. field c has been initialized first and then field i has been initialized.
D. No compile error and it ll print 100 A.
Answer» E.
28.

Pick the best statement for the below program:

 #include "stdio.h" int main() { struct {int a[2], b;} arr[] = {[0].a = {1}, [1].a = {2}, [0].b = 1, [1].b = 2}; printf("%d %d ?nd",arr[0].a[0],arr[0].a[1],arr[0].b); printf("%d %d %dn",arr[1].a[0],arr[1].a[1],arr[1].b); return 0; }

A. Compile error because struct type (containing two fields i.e. an array of int and an int) has been specified along with the definition of array arr[] of this struct type.
B. Compile error because of incorrect syntax for initialization of array arr[].
C. No compile error and two elements of arr[] would be defined and initialized. Output would be 1 0 1 and 2 0 2 .
D. No compile error and two elements of arr[] would be defined and initialized. Output would be 1 X 1 and 2 X 2 where X is some garbage random number.
Answer» D. No compile error and two elements of arr[] would be defined and initialized. Output would be 1 X 1 and 2 X 2 where X is some garbage random number.
29.

Size of a union is determined by size of the.

A. First member in the union
B. Last member in the union
C. Sum of the sizes of all members
D. Biggest member in the union
Answer» E.
30.

Which of the following share a similarity in syntax? 1. Union 2. Structure 3. Arrays 4. Pointers

A. 3 and 4
B. 1 and 2
C. 2 and 3
D. All of the above
Answer» C. 2 and 3
31.

Members of a union are accessed as________________.

A. union-name.member
B. union-pointer->member
C. Both a & b
D. None of the mentioned
Answer» D. None of the mentioned
32.

The size of the following union, where an int occupies 4 bytes of memory is

 union demo { float x; int y; char z[10]; };

A. 8 byte
B. 4 byte
C. 10 byte
D. 18 byte
Answer» D. 18 byte
33.

Union differs from structure in the following way

A. All members are used at a time
B. Only one member can be used at a time
C. Union cannot have more members
D. Union initialized all members as structure
Answer» C. Union cannot have more members
34.

What is the correct syntax to declare a function foo() which receives an array of structure in function?

A. void foo(struct *var);
B. void foo(struct *var[]);
C. void foo(struct var);
D. none of the mentioned
Answer» B. void foo(struct *var[]);
35.

Pick the best statement for the below program snippet:

 struct {int a[2];} arr[] = {1,2};

A. No compile error and it ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[1].a[0] would be 2.
B. No compile error and it ll create array arr of 2 elements. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2. The second element arr[1] would be ZERO i.e. arr[1].a[0] and arr[1].a[1] would be 0.
C. No compile error and it ll create array arr of 1 element. Each of the element of arr contain a struct field of int array of 2 elements. arr[0]. a[0] would be 1 and arr[0].a[1] would be 2.
Answer» D.
36.

Pick the best statement for the below program:

 #include "stdio.h" int main() { struct {int a[2];} arr[] = {{1},{2}}; printf("%d %d %d %d",arr[0].a[0],arr[0].a[1],arr[1].a[0],arr[1].a[1]); return 0; }

A. Compile error because arr has been defined using struct type incorrectly. First struct type should be defined using tag and then arr should be defined using that tag.
B. Compile error because apart from definition of arr, another issue is in the initialization of array of struct i.e. arr[].
C. Compile error because of initialization of array of struct i.e. arr[].
D. No compile error and it ll print 1 0 2 0
Answer» E.
37.

In the following program snippet, both s1 and s2 would be variables of structure type defined as below and there won't be any compilation issue.

 typedef struct Student { int rollno; int total; } Student; Student s1; struct Student s2;

A. TRUE
B. FALSE
Answer» B. FALSE
38.

Anyone of the following can be used to declare a node for a singly linked list and NODEPTR nodePtr; can be used to declare pointer to a node using any of the following

 /* First declaration */ typedef struct node { int data; struct node *nextPtr; }* NODEPTR; /* Second declaration */ struct node { int data; struct node * nextPtr; }; typedef struct node * NODEPTR;

A. TRUE
B. FALSE
Answer» B. FALSE
39.

Predict the output of following C program

 #include struct Point { int x, y, z; }; int main() { struct Point p1 = {.y = 0, .z = 1, .x = 2}; printf("%d %d %d", p1.x, p1.y, p1.z); return 0; }

A. Compiler Error
B. 2 0 1
C. 0 1 2
D. 2 1 0
E.
Answer» C. 0 1 2
40.

Anyone of the followings can be used to declare a node for a singly linked list. If we use the first declaration, struct node * nodePtr; would be used to declare pointer to a node. If we use the second declaration, NODEPTR nodePtr; can be used to declare pointer to a node.

 /* First declaration */ struct node { int data; struct node * nextPtr; }; /* Second declaration */ typedef struct node{ int data; NODEPTR nextPtr; } * NODEPTR;

A. TRUE
B. FALSE
Answer» C.
41.

The following C declarations

 struct node { int i; float j; }; struct node *s[10] ;

define s to be

A. An array, each element of which is a pointer to a structure of type node
B. A structure of 2 fields, each field being a pointer to an array of 10 elements
C. A structure of 3 fields: an integer, a float, and an array of 10 elements
D. An array, each element of which is a structure of type node.
Answer» B. A structure of 2 fields, each field being a pointer to an array of 10 elements
42.

Which of the following operators can be applied on structure variables?

A. Equality comparison ( == )
B. Assignment ( = )
C. Both of the above
D. None of the above
Answer» C. Both of the above
43.

Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed.

 union test { int x; char arr[8]; int y; }; int main() { printf("%d", sizeof(union test)); return 0; }

A. 12
B. 16
C. 8
D. Compiler Error
Answer» D. Compiler Error
44.

Point out the error (if any) in the following C code?

 #include enum hello { a,b,c; }; main() { enum hello m; printf("%d",m); }

A. No error
B. Error in the statement: a,b,c;
C. Error in the statement: enum hello m;
D. Error in the statement: printf( %d ,m);
Answer» C. Error in the statement: enum hello m;
45.

What will be the output of the following C code?

 #include enum colour { blue, red, yellow }; main() { enum colour c; c=yellow; printf("%d",c); }

A. 1
B. 2
C. Error
Answer» A. 1
46.

A user defined data type, which is used to assign names to integral constants is called ____________

A. Union
B. Array
C. Structure
D. Enum
Answer» E.
47.

The number of distinct nodes the following struct declaration can point to is

 struct node { struct node *left; struct node *centre; struct node *right; };

A. All of the above
B. 1
C. 2
D. 3
Answer» B. 1
48.

The correct syntax to access the member of the ith structure in the array of structures is?

 Assuming: struct temp { int b; }s[50];

A. s.b.[i];
B. s.[i].b;
C. s.b[i];
D. s[i].b;
Answer» E.
49.

Arithmetic operations such as addition, subtraction, multiplication and division are allowed on enumerated constants.

A. True
B. False
Answer» B. False
50.

What will be the output of the following C code?

 #include enum hi{a,b,c}; enum hello{c,d,e}; main() { enum hi h; h=b; printf("%d",h); return 0; }

A. 2
B. 1
C. Error
Answer» D.