ExamVeda
Login
Home
11
What is the size of the following structure in C++: struct Employee { int id; char name[20]; float salary; };
Discuss
Answer & Solution
Answer: Option D
Solution:
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.
12
What is the correct syntax to define a structure pointer in C++?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
13
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++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
14
What is the purpose of using unions in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
15
What does the 'sizeof' operator return when used with a structure in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
16
What is the correct syntax to declare a structure with a tag name in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
17
What is the correct way to access structure members through a pointer in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
18
What is the difference between a structure and a class in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
19
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++?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
20
What is the purpose of the 'typedef' keyword in C++ structures?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board