Structure And Union — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Structure And Union — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Find the output of the following program: void main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d", s->x); printf("%s", s->name); }
Correct Answer: Option D — Compilation error
Detailed Academic Explanation:
You cannot initialize members in structure declaration.
💡Key Conceptual Anchor:Structure And Union
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following code. struct account{ int acno; }svar, *pv = &svar; then the acno can be accessed by
Correct Answer: Option D — A, B and C
Detailed Academic Explanation:
As all the ways are legal and valid.
💡Key Conceptual Anchor:Structure And Union
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Consider the following declarations: union id { char color; int size; }; struct{ char country; int date; union id id; }flag; To assign a color to a flag, the correct statement would be
Correct Answer: Option A — flag.color = 'W'
Detailed Academic Explanation:
Solution: 2
💡Key Conceptual Anchor:Structure And Union
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
For the following structure declaration, find the correct statement. struct person{ char name[20]; int age; struct person lady; };
Correct Answer: Option D — Is not a valid nested structure.
Detailed Academic Explanation:
As we cannot create a variable of itself as a member of the structure, but a reference can be created to create a self referential structure.
💡Key Conceptual Anchor:Structure And Union
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The restriction with union is
Correct Answer: Option A — The first member can only be initialized.
Detailed Academic Explanation:
As all the members shares the same memory.
💡Key Conceptual Anchor:Structure And Union
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C code? #include <stdio.h> struct p { char *name; struct p *next; }; struct p *ptrary[10]; int main() { struct p p, q; p.name = "xyz"; p.next = NULL; ptrary[0] = &p; strcpy(q.name, p.name); ptrary[1] = &q; printf("%s\n", ptrary[1]->name); return 0; }
Correct Answer: Option B — Segmentation fault/code crash
Detailed Academic Explanation:
In this code, the variable q is declared but not initialized. When you try to use strcpy function to copy the value of p.name to q.name , you are accessing memory that has not been allocated for q.name , which leads to undefined behavior. This undefined behavior could result in a segmentation fault or a code crash. Therefore, the correct answer is Option B: Segmentation fault/code crash.
💡Key Conceptual Anchor:Structure And Union
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the keyword used to define a structure in C?
Correct Answer: Option A — struct
Detailed Academic Explanation:
struct is the correct answer to “What is the keyword used to define a structure in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a structure, what are the members also known as?
Correct Answer: Option A — Variables
Detailed Academic Explanation:
Variables is the correct answer to “In a structure, what are the members also known as”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following can be a member of a structure?
Correct Answer: Option B — Another structure
Detailed Academic Explanation:
Another structure is the correct answer to “Which of the following can be a member of a structure”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you access a member of a structure in C?
Correct Answer: Option A — . (dot)
Detailed Academic Explanation:
. (dot) is the correct answer to “How do you access a member of a structure in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the primary difference between a structure and a union in C?
Correct Answer: Option D — Union allows only one active member
Detailed Academic Explanation:
Union allows only one active member is the correct answer to “What is the primary difference between a structure and a union in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is the size of a structure determined in C?
Correct Answer: Option B — By the size of its largest member
Detailed Academic Explanation:
By the size of its largest member is the correct answer to “How is the size of a structure determined in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which statement correctly defines a structure named "Person" with members "name" and "age" of type char* and int respectively?
Correct Answer: Option A — struct Person { char* name; int age; }
Detailed Academic Explanation:
struct Person { char* name; int age; } is the correct answer to “Which statement correctly defines a structure named "Person" with members "name" and "age" of type char* and int respectively”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'sizeof' operator in C return for a union?
Correct Answer: Option B — Size of the largest member
Detailed Academic Explanation:
Size of the largest member is the correct answer to “What does the 'sizeof' operator in C return for a union”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Can a structure have another structure as a member in C?
Correct Answer: Option C — Yes, without any limitations
Detailed Academic Explanation:
Yes, without any limitations is the correct answer to “Can a structure have another structure as a member in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which operator is used to access a union member when the union is a part of a structure?
Correct Answer: Option A — . (dot)
Detailed Academic Explanation:
. (dot) is the correct answer to “Which operator is used to access a union member when the union is a part of a structure”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens when you assign a value to one member of a union and then access another member in C?
Correct Answer: Option B — It leads to undefined behavior
Detailed Academic Explanation:
It leads to undefined behavior is the correct answer to “What happens when you assign a value to one member of a union and then access another member in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to define an anonymous structure or union within another structure or union?
Correct Answer: Option C — struct
Detailed Academic Explanation:
struct is the correct answer to “Which keyword is used to define an anonymous structure or union within another structure or union”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In a union, which member can you access safely after assigning a value to one of its members?
Correct Answer: Option C — Only the first assigned member
Detailed Academic Explanation:
Only the first assigned member is the correct answer to “In a union, which member can you access safely after assigning a value to one of its members”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which type of variable should you use if you want to store different types of data at different times within the same memory location?
Correct Answer: Option D — union
Detailed Academic Explanation:
union is the correct answer to “Which type of variable should you use if you want to store different types of data at different times within the same memory location”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is true about the memory allocation of structures and unions in C?
Correct Answer: Option C — Structures allocate memory for the largest member
Detailed Academic Explanation:
Structures allocate memory for the largest member is the correct answer to “Which of the following is true about the memory allocation of structures and unions in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, can a structure be passed as an argument to a function?
Correct Answer: Option B — Yes, by reference
Detailed Academic Explanation:
Yes, by reference is the correct answer to “In C, can a structure be passed as an argument to a function”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of using a typedef with structures and unions in C?
Correct Answer: Option A — To create a new data type name for the structure or union
Detailed Academic Explanation:
To create a new data type name for the structure or union is the correct answer to “What is the purpose of using a typedef with structures and unions in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When should you use a structure instead of an array in C?
Correct Answer: Option A — When you need to store elements of different data types
Detailed Academic Explanation:
When you need to store elements of different data types is the correct answer to “When should you use a structure instead of an array in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of an anonymous union in C?
Correct Answer: Option B — To declare a union without a name
Detailed Academic Explanation:
To declare a union without a name is the correct answer to “What is the purpose of an anonymous union in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to access a member of a nested structure in C?
Correct Answer: Option A — . (dot)
Detailed Academic Explanation:
. (dot) is the correct answer to “Which keyword is used to access a member of a nested structure in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the main advantage of using a union in C?
Correct Answer: Option A — It saves memory by sharing the same memory location
Detailed Academic Explanation:
It saves memory by sharing the same memory location is the correct answer to “What is the main advantage of using a union in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the size of an empty structure in C?
Correct Answer: Option A — 0 bytes
Detailed Academic Explanation:
0 bytes is the correct answer to “What is the size of an empty structure in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, can you compare two structures using the equality operator (==)?
Correct Answer: Option B — No, never
Detailed Academic Explanation:
No, never is the correct answer to “In C, can you compare two structures using the equality operator (==)”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the primary use of a union in a C program?
Correct Answer: Option A — To represent multiple data types using the same memory location
Detailed Academic Explanation:
To represent multiple data types using the same memory location is the correct answer to “What is the primary use of a union in a C program”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you declare an array of structures in C?
Correct Answer: Option B — myStruct array[]
Detailed Academic Explanation:
myStruct array[] is the correct answer to “How do you declare an array of structures in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not a valid type for a structure member in C?
Correct Answer: Option C — Function
Detailed Academic Explanation:
Function is the correct answer to “Which of the following is not a valid type for a structure member in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, can you have a structure as a member of itself (a recursive structure)?
Correct Answer: Option A — Yes, but with compiler-specific limitations
Detailed Academic Explanation:
Yes, but with compiler-specific limitations is the correct answer to “In C, can you have a structure as a member of itself (a recursive structure)”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the offsetof macro in C?
Correct Answer: Option A — To calculate the offset of a structure member
Detailed Academic Explanation:
To calculate the offset of a structure member is the correct answer to “What is the purpose of the offsetof macro in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to create a new name for an existing data type in C?
Correct Answer: Option A — typedef
Detailed Academic Explanation:
typedef is the correct answer to “Which keyword is used to create a new name for an existing data type in C”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many union members can be initialized?
Correct Answer: Option A — Only one member of a union at any one time.
Detailed Academic Explanation:
Only one member of a union at any one time. is the correct answer to “How many union members can be initialized”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C code? #include <stdio.h> int main() { typedef struct p *q; struct p { int x; char y; q ptr; }; struct p p = {1, 2, &p}; printf("%d\n", p.ptr->x); return 0; }
Correct Answer: Option B — 1
Detailed Academic Explanation:
1 is the correct answer to “What will be the output of the following C code? #include <stdio.h> int main() { typedef struct p *q; struct p { int x; char y; q ptr; }; struct p p = {1, 2, &p}; printf("%d\n", p.ptr->x); return 0; }”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Can the following C code be compiled successfully? #include <stdio.h> struct p { int k; char c; float f; }; int main() { struct p x = {.c = 97, .f = 3, .k = 1}; printf("%f\n", x.f); }
Correct Answer: Option C — Depends on the standard
Detailed Academic Explanation:
Depends on the standard is the correct answer to “Can the following C code be compiled successfully? #include <stdio.h> struct p { int k; char c; float f; }; int main() { struct p x = {.c = 97, .f = 3, .k = 1}; printf("%f\n", x.f); }”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C code? #include <stdio.h> int *(*(x()))[2]; typedef int **(*ptrfoo)())[2]; int main() { ptrfoo ptr1; ptr1 = x; ptr1(); return 0; } int *(*(x()))[2] { int (*ary)[2] = malloc(sizeof * ary); return &ary; }
Correct Answer: Option B — Nothing
Detailed Academic Explanation:
Nothing is the correct answer to “What will be the output of the following C code? #include <stdio.h> int *(*(x()))[2]; typedef int **(*ptrfoo)())[2]; int main() { ptrfoo ptr1; ptr1 = x; ptr1(); return 0; } int *(*(x()))[2] { int (*ary)[2] = malloc(sizeof * ary); return &ary; }”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following share a similarity in syntax? 1. Union, 2. Structure, 3. Arrays and 4. Pointers
Correct Answer: Option B — 1 and 2
Detailed Academic Explanation:
1 and 2 is the correct answer to “Which of the following share a similarity in syntax? 1. Union, 2. Structure, 3. Arrays and 4. Pointers”. This question is standard in competitive examination syllabi for Structure And Union.
💡Key Conceptual Anchor:Structure And Union
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.