What will the following code snippet print?
int num = 10; while (num > 0) { num = num - 2; cout << num << " "; }
10 8 6 4 2 0
10 8 6 4 2
9 7 5 3 1
8 6 4 2 0
Which data type is used to store whole numbers without any decimal points?
string
float
double
int
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'
If 'func' is a function that takes an integer and returns void, how would you call this function using a pointer 'ptr' to the function?
*ptr(5);
ptr(5);
func(ptr, 5);
&ptr(5);
Which principle of OOP emphasizes hiding internal details and exposing only essential information?
Inheritance
Polymorphism
Abstraction
Encapsulation
What is the purpose of the 'break' statement in a switch-case statement?
To jump to a specific case statement
To repeat the current case statement
To exit the switch-case statement
To skip to the next case statement
Which of the following is NOT a valid way to initialize a character array in C++?
char message[5] = "Hello";
char message[] = "Hello";
char message[10] = "Hello";
char message[10] = {'H', 'e', 'l', 'l', 'o'};
What is an inline function in C++?
A function that does not return any value.
A function that is defined inside another function.
A function that takes another function as a parameter.
A function that is declared with the 'inline' keyword, which serves as a request to the compiler to replace the function call with its actual code.
Which of the following accesses the third element of an integer array named 'data'?
data.third
data.2
data[2]
data[3]
What C++ function can you use to find the length of a C-style string (character array)?
strlen()
str_length()
length()
size()