Question 1 of 25
Hints left: 3
Q1
What is the output of the following code: struct Book { char title[50]; int pages; }; Book b; cout << sizeof(b); in C++?
Q2
What is the purpose of the 'typedef' keyword in C++ structures?
Q3
What is the size of the following structure in C++: struct Employee { int id; char name[20]; float salary; };
Q4
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; }
Q5
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++?
Q6
What does the 'sizeof' operator return when used with a structure in C++?
Q7
What is the purpose of using unions in C++?
Q8
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++?
Q9
What is the difference between a structure and a class in C++?
Q10
Which of the following is a properly defined structure?
Q11
What is a dangling pointer in C++?
Q12
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; }
Q13
The declaration of the structure is also called as?
Q14
What is the correct syntax to declare a structure with a tag name in C++?
Q15
What is the output of the following code: union Number { int x; float y; }; Number n; n.x = 10; cout << n.y; in C++?
Q16
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; }
Q17
What is the correct syntax to define a union in C++?
Q18
What is the correct syntax to define a structure pointer in C++?
Q19
What will be used when terminating a structure?
Q20
Which keyword is used to declare a union in C++?
Q21
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; }
Q22
What is the correct way to access structure members through a pointer in C++?
Q23
Which of the following accesses a variable in structure *b?
Q24
What will happen when the structure is declared?
Q25
The data elements in the structure are also known as what?