What C++ function can you use to find the length of a C-style string (character array)?
strlen()
str_length()
length()
size()
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?
\0
\n
.
'\0'
How can you prevent a C++ class from being inherited from?
By using the 'abstract' keyword
By declaring it with the 'final' keyword
By not defining any constructors
By making all its members private
What is the output of the following code snippet?
int i = 10; do { cout << i << " "; i--; } while (i > 10);
9 8 7 6 5 4 3 2 1 0
10 9 8 7 6 5 4 3 2 1
The loop will run infinitely
10
What is the output of the following code snippet: cout << (5 > 3 && 10 < 20);?
cout << (5 > 3 && 10 < 20);
0
1
3
5
What is the correct way to receive user input in C++ and store it in a variable named 'name'?
cin >> name;
input name;
scanf name;
cout << name;
What will the following code snippet print?
int num = 10; while (num > 0) { num = num - 2; cout << num << " "; }
9 7 5 3 1
8 6 4 2 0
10 8 6 4 2 0
10 8 6 4 2
Which of these is NOT a benefit of using functions in programming?
Easier debugging and maintenance
Improved code organization
Code reusability
Increased memory usage
What is the primary purpose of a constructor in a C++ class?
To implement polymorphism
To free up memory when an object is destroyed
To define the class's interface
To initialize object members when an object is created
What is a pure virtual function in C++?
A function that can be called before an object is created
A function with no implementation in the base class, meant to be overridden by derived classes
A function that creates new data types
A function that automatically destroys an object