11
What is the purpose of the 'using' directive in C++?
A)
To define a new namespace
B)
To declare a variable
C)
To declare a function
D)
To introduce a name from a namespace into the current scope
Answer & Solution
Answer: Option
D
12
Which of the following is not a valid C++ data type?
A)
long long
B)
long double
C)
unsigned float
D)
wchar_t
Answer & Solution
Answer: Option
C
13
What is the purpose of the typeid operator in C++?
A)
To return the type of an expression
B)
To return the memory address of a type
C)
To compare two types
D)
To perform type casting
Answer & Solution
Answer: Option
A
14
What does the mutable keyword in C++ mean when applied to a class member function?
A)
It specifies that the member function cannot be overridden
B)
It specifies that the member function does not modify the object's data members
C)
It allows the member function to modify the object's data members declared as static
D)
It allows the member function to modify the object's data members declared as const
Answer & Solution
Answer: Option
D
15
Which of the following correctly defines a lambda function in C++?
A)
lambda(int x, int y) { return x + y; };
B)
function lambda(int x, int y) { return x + y; };
C)
auto lambda = [](int x, int y) { return x + y; };
D)
auto lambda(int x, int y) -> int { return x + y; };
Answer & Solution
Answer: Option
C
16
What is the purpose of the static_cast operator in C++?
A)
To perform implicit type conversions
B)
To perform explicit type conversions
C)
To access static class members
D)
None of the above
Answer & Solution
Answer: Option
B
17
Which of the following is not a valid way to initialize an array in C++?
A)
int arr[5] = {1, 2, 3, 4, 5};
B)
int arr[] = {1, 2, 3, 4, 5};
C)
int arr[5] {1, 2, 3, 4, 5};
D)
int arr[5]; arr = {1, 2, 3, 4, 5};
Answer & Solution
Answer: Option
D
18
What does the nullptr keyword represent in C++?
A)
A null pointer value
B)
A reference to a null pointer
C)
An empty string
D)
An integer value
Answer & Solution
Answer: Option
A
19
What is the purpose of the std::move function in C++?
A)
To access static class members
B)
To allocate memory dynamically
C)
To perform explicit type conversions
D)
To cast an object to an rvalue reference
Answer & Solution
Answer: Option
D
20
What is the purpose of the std::initializer_list class in C++?
A)
To store a list of initializers
B)
To initialize class objects with a list of values at runtime
C)
To initialize containers with a list of values at compile time
D)
To allocate memory dynamically
Answer & Solution
Answer: Option
C