Which of the following is NOT a valid C++ function definition?
void printMessage();
int sum(int a, int b) { return a + b; }
double calculateArea(double radius) { return 3.14 * radius * radius; }
string greet(string name) { cout << "Hello, " << name << "!" << endl; }
Which of the following accesses the third element of an integer array named 'data'?
data[3]
data.third
data.2
data[2]
What is the output of the following code snippet: cout << (5 > 3 && 10 < 20);?
cout << (5 > 3 && 10 < 20);
1
5
3
0
What is the primary purpose of a constructor in a C++ class?
To initialize object members when an object is created
To free up memory when an object is destroyed
To define the class's interface
To implement polymorphism
What is the output of the following C++ code snippet?
#include <iostream> int main() { int x = 5; int y = 10; int result = (x, y); std::cout << result; return 0; }
15
Compilation Error
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 switch-case statement is skipped.
The program enters an infinite loop.
The behavior is undefined.
Which data type is used to store whole numbers without any decimal points?
float
double
int
string
Which C++ library provides functions for string manipulation, such as copying, concatenation, and comparison?
#include <string>
#include <cstring>
#include <array>
#include <iostream>
What is the correct syntax to declare a pointer variable named 'ptr' that points to an integer?
*int ptr;
int &ptr;
int *ptr;
ptr int;
Which principle of OOP emphasizes hiding internal details and exposing only essential information?
Abstraction
Encapsulation
Inheritance
Polymorphism