Structures And Unions In C Plus Plus MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Structures And Unions In C Plus Plus with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
34
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
41 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
34
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/34 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 34 questions answered.
Question 1 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the size of the following structure in C++: struct Employee { int id; char name[20]; float salary; };
Correct Answer: Option D — 32 bytes
Detailed Academic Explanation:
In C++, the size of a structure is determined by the sum of the sizes of its individual members, taking into account padding for alignment. The Employee structure consists of three members: an integer id , an array of characters name of size 20, and a float salary . The size of an integer is typically 4 bytes, the size of a float is also typically 4 bytes, and the size of each character in the array depends on the character set being used (usually 1 byte per character). However, due to memory alignment requirements, additional padding may be added after the name array to ensure proper alignment of subsequent members. So, the calculation of the structure size would be: int id : 4 bytes char name[20] : 20 bytes Padding to align salary to the next 4-byte boundary (assuming 4-byte alignment) float salary : 4 bytes Total: 4 bytes (id) + 20 bytes (name) + 4 bytes (padding) + 4 bytes (salary) = 32 bytes. Therefore, the correct answer is Option D: 32 bytes.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 2 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a structure in C++?
Correct Answer: Option C — A user-defined data type containing variables of different data types
Detailed Academic Explanation:
A user-defined data type containing variables of different data types is the correct answer to “What is a structure in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 3 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to define a structure in C++?
Correct Answer: Option B — struct
Detailed Academic Explanation:
struct is the correct answer to “Which keyword is used to define a structure in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 4 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to access members of a structure in C++?
Correct Answer: Option C — Using the dot operator
Detailed Academic Explanation:
Using the dot operator is the correct answer to “What is the correct way to access members of a structure in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 5 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of typedef in C++ structures?
Correct Answer: Option D — To create an alias for data types
Detailed Academic Explanation:
To create an alias for data types is the correct answer to “What is the purpose of typedef in C++ structures”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 6 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you declare a structure variable in C++?
Correct Answer: Option A — structName variableName
Detailed Academic Explanation:
structName variableName is the correct answer to “How do you declare a structure variable in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 7 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: struct Student { int roll; }; Student s1; s1.roll = 101; cout << s1.roll; in C++?
Correct Answer: Option D — 101
Detailed Academic Explanation:
101 is the correct answer to “What is the output of the following code: struct Student { int roll; }; Student s1; s1.roll = 101; cout << s1.roll; in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 8 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of using structures in C++?
Correct Answer: Option C — To group related data together
Detailed Academic Explanation:
To group related data together is the correct answer to “What is the purpose of using structures in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 9 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to pass a structure to a function in C++?
Correct Answer: Option D — All of the above
Detailed Academic Explanation:
All of the above is the correct answer to “What is the correct way to pass a structure to a function in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 10 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a union in C++?
Correct Answer: Option B — A user-defined data type that allows storing different data types in the same memory location
Detailed Academic Explanation:
A user-defined data type that allows storing different data types in the same memory location is the correct answer to “What is a union in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 11 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between a structure and a union in C++?
Correct Answer: Option C — In a structure, each member has its own memory space, while in a union, all members share the same memory space
Detailed Academic Explanation:
In a structure, each member has its own memory space, while in a union, all members share the same memory space is the correct answer to “What is the difference between a structure and a union in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 12 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax to define a structure pointer in C++?
Correct Answer: Option A — structName *ptr
Detailed Academic Explanation:
structName *ptr is the correct answer to “What is the correct syntax to define a structure pointer in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 13 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: union Data { int x; char y; }; Data d; d.x = 10; d.y = 'A'; cout << d.x << " " << d.y; in C++?
Correct Answer: Option D — 0.416666667
Detailed Academic Explanation:
0.416666667 is the correct answer to “What is the output of the following code: union Data { int x; char y; }; Data d; d.x = 10; d.y = 'A'; cout << d.x << " " << d.y; in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 14 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of using unions in C++?
Correct Answer: Option C — To save memory space
Detailed Academic Explanation:
To save memory space is the correct answer to “What is the purpose of using unions in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 15 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'sizeof' operator return when used with a structure in C++?
Correct Answer: Option C — Size of the structure
Detailed Academic Explanation:
Size of the structure is the correct answer to “What does the 'sizeof' operator return when used with a structure in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 16 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax to declare a structure with a tag name in C++?
Correct Answer: Option D — struct structName { /* members */ }
Detailed Academic Explanation:
struct structName { /* members */ } is the correct answer to “What is the correct syntax to declare a structure with a tag name in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 17 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to access structure members through a pointer in C++?
Correct Answer: Option D — Using the arrow operator (->)
Detailed Academic Explanation:
Using the arrow operator (->) is the correct answer to “What is the correct way to access structure members through a pointer in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 18 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between a structure and a class in C++?
Correct Answer: Option C — By default, members of a class are private, while members of a structure are public
Detailed Academic Explanation:
By default, members of a class are private, while members of a structure are public is the correct answer to “What is the difference between a structure and a class in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 19 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: struct Point { int x, y; }; Point p1; p1.x = 10; p1.y = 20; cout << p1.x << " " << p1.y; in C++?
Correct Answer: Option B — 10 20
Detailed Academic Explanation:
10 20 is the correct answer to “What is the output of the following code: struct Point { int x, y; }; Point p1; p1.x = 10; p1.y = 20; cout << p1.x << " " << p1.y; in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 20 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'typedef' keyword in C++ structures?
Correct Answer: Option C — To create an alias for a data type
Detailed Academic Explanation:
To create an alias for a data type is the correct answer to “What is the purpose of the 'typedef' keyword in C++ structures”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 21 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to declare a union in C++?
Correct Answer: Option D — union
Detailed Academic Explanation:
union is the correct answer to “Which keyword is used to declare a union in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 22 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax to define a union in C++?
Correct Answer: Option A — union unionName { /* members */ }
Detailed Academic Explanation:
union unionName { /* members */ } is the correct answer to “What is the correct syntax to define a union in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 23 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: struct Book { char title[50]; int pages; }; Book b; cout << sizeof(b); in C++?
Correct Answer: Option B — Depends on the compiler
Detailed Academic Explanation:
Depends on the compiler is the correct answer to “What is the output of the following code: struct Book { char title[50]; int pages; }; Book b; cout << sizeof(b); in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 24 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: union Number { int x; float y; }; Number n; n.x = 10; cout << n.y; in C++?
Correct Answer: Option C — Garbage value
Detailed Academic Explanation:
Garbage value is the correct answer to “What is the output of the following code: union Number { int x; float y; }; Number n; n.x = 10; cout << n.y; in C++”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 25 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The declaration of the structure is also called as?
Correct Answer: Option C — structure specifier
Detailed Academic Explanation:
structure specifier is the correct answer to “The declaration of the structure is also called as”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 26 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }
Correct Answer: Option A — 252
Detailed Academic Explanation:
252 is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; struct sec { int a; char b; }; int main() { struct sec s ={25,50}; struct sec *ps =(struct sec *)&s; cout << ps->a << ps->b; return 0; }”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 27 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; struct Time { int hours; int minutes; int seconds; }; int toSeconds(Time now); int main() { Time t; t.hours = 5; t.minutes = 30; t.seconds = 45; cout << "Total seconds: " << toSeconds(t) << endl; return 0; } int toSeconds(Time now) { return 3600 * now.hours + 60 * now.minutes + now.seconds; }
Correct Answer: Option A — 19845
Detailed Academic Explanation:
19845 is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; struct Time { int hours; int minutes; int seconds; }; int toSeconds(Time now); int main() { Time t; t.hours = 5; t.minutes = 30; t.seconds = 45; cout << "Total seconds: " << toSeconds(t) << endl; return 0; } int toSeconds(Time now) { return 3600 * now.hours + 60 * now.minutes + now.seconds; }”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 28 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string.h> using namespace std; int main() { struct student { int num; char name[25]; }; student stu; stu.num = 123; strcpy(stu.name, "John"); cout << stu.num << endl; cout << stu.name << endl; return 0; }
Correct Answer: Option A — 123 john
Detailed Academic Explanation:
123 john is the correct answer to “What will be the output of the following C++ code? #include <iostream> #include <string.h> using namespace std; int main() { struct student { int num; char name[25]; }; student stu; stu.num = 123; strcpy(stu.name, "John"); cout << stu.num << endl; cout << stu.name << endl; return 0; }”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 29 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be used when terminating a structure?
Correct Answer: Option C —
Detailed Academic Explanation:
is the correct answer to “What will be used when terminating a structure”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 30 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The data elements in the structure are also known as what?
Correct Answer: Option B — members
Detailed Academic Explanation:
members is the correct answer to “The data elements in the structure are also known as what”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 31 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is a properly defined structure?
Correct Answer: Option D — struct a_struct {int a;}
Detailed Academic Explanation:
struct a_struct {int a;} is the correct answer to “Which of the following is a properly defined structure”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 32 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen when the structure is declared?
Correct Answer: Option A — it will not allocate any memory
Detailed Academic Explanation:
it will not allocate any memory is the correct answer to “What will happen when the structure is declared”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 33 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { struct ShoeType { string style; double price; }; ShoeType shoe1, shoe2; shoe1.style = "Adidas"; shoe1.price = 9.99; cout << shoe1.style << " $ "<< shoe1.price; shoe2 = shoe1; shoe2.price = shoe2.price / 9; cout << shoe2.style << " $ "<< shoe2.price; return 0; }
Correct Answer: Option A — Adidas $ 9.99Adidas $ 1.11
Detailed Academic Explanation:
Adidas $ 9.99Adidas $ 1.11 is the correct answer to “What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { struct ShoeType { string style; double price; }; ShoeType shoe1, shoe2; shoe1.style = "Adidas"; shoe1.price = 9.99; cout << shoe1.style << " $ "<< shoe1.price; shoe2 = shoe1; shoe2.price = shoe2.price / 9; cout << shoe2.style << " $ "<< shoe2.price; return 0; }”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
Question 34 of 34
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following accesses a variable in structure *b?
Correct Answer: Option A — b->var
Detailed Academic Explanation:
b->var is the correct answer to “Which of the following accesses a variable in structure *b”. This question is standard in competitive examination syllabi for Structures And Unions In C Plus Plus.
💡Key Conceptual Anchor:Structures And Unions In C Plus Plus
✓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.