What is the correct way to declare a constant variable named 'PI' with the value 3.14159?
const float PI 3.14159;
#define PI = 3.14159
constant PI = 3.14159;
const float PI = 3.14159;
If 'ptr' is a pointer to an integer variable 'num', how would you access the value stored in 'num' using 'ptr'?
&ptr
*ptr
ptr
num
In C++, a character array can be used to store a string. What is the special character that signifies the end of a string in a character array?
\n
\0
.
'\0'
Which principle of OOP emphasizes hiding internal details and exposing only essential information?
Abstraction
Inheritance
Polymorphism
Encapsulation
What does the 'protected' access specifier in C++ control?
Accessibility from anywhere in the program
Accessibility only within the same file
Accessibility within the same class and derived classes
Accessibility within the same class only
What is the output of the following code snippet: cout << (5 > 3 && 10 < 20);?
cout << (5 > 3 && 10 < 20);
3
5
1
0
What will the following C++ code snippet print?
#include <iostream> void changeValue(int x) { x = 100; } int main() { int num = 50; changeValue(num); std::cout << num; return 0; }
None of the above
100
50
How do you declare a multi-dimensional array (specifically, a 2D array) in C++?
array matrix[3, 4];
int matrix(3)(4);
int matrix[3, 4];
int matrix[3][4];
What is the output of the following code snippet?
int i = 10; do { cout << i << " "; i--; } while (i > 10);
10 9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1 0
The loop will run infinitely
10
In a switch-case statement, what happens if no case matches the switch expression and there is no 'default' case?
A compilation error occurs.
The behavior is undefined.
The program enters an infinite loop.
The switch-case statement is skipped.