What is the correct way to pass a pointer to a function in C++?
A. By reference
B. By value
C. By dereferencing the pointer
D. By declaring the pointer globally
Select an option to see the answer and solution.
What is a memory leak in C++?
A. Failure to allocate memory when needed
B. Allowing memory to be accessed by unauthorized users
C. Accessing an invalid memory location
D. Failure to deallocate memory after it's no longer needed
Select an option to see the answer and solution.
What is the purpose of the 'delete' keyword in C++?
A. Deletes a variable
B. Deletes a pointer
C. Deallocates memory dynamically
D. Deallocates memory statically
Select an option to see the answer and solution.
What does the 'nullptr' keyword signify when used as a pointer value in C++?
A. A pointer to a null reference
B. A null pointer
C. A pointer to a null object
D. None of the above
Select an option to see the answer and solution.
What is a pointer arithmetic in C++?
A. Assigning arithmetic expressions to a pointer
B. Using pointers to perform arithmetic operations
C. Performing arithmetic operations on pointers
D. Storing arithmetic operations in a pointer
Select an option to see the answer and solution.
What is the purpose of the 'this' pointer in C++?
A. Points to the next object instance
B. Points to the previous object instance
C. Points to the base class object instance
D. Points to the current object instance
Select an option to see the answer and solution.
What is the output of the following code: char str[] = "Hello"; cout << sizeof(str); in C++?
A. 5
B. 4
C. Compilation error
D. 6
Select an option to see the answer and solution.
What does the 'sizeof' operator return when used with a pointer variable in C++?
A. Size of the pointer variable
B. Size of the data type pointed to by the pointer
C. Address of the pointer variable
D. Address of the data pointed to by the pointer
Select an option to see the answer and solution.
What is the purpose of the 'const' keyword in a pointer declaration in C++?
A. Indicates that the pointer itself is constant
B. Indicates that the value pointed to is constant
C. Indicates that the pointer can be reassigned
D. Indicates that the pointer points to a constant value
Select an option to see the answer and solution.
What is the output of the following code: int arr[3] = {1, 2, 3}; cout << *(arr + 2); in C++?
A. 1
B. 2
C. 3
D. Compilation error
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int const p = 5;
cout << ++p;
return 0;
}Select an option to see the answer and solution.
What we can't do on a void pointer?
A. pointer arithmetic
B. pointer functions
C. pointer objects
D. pointer functions & objects
Select an option to see the answer and solution.
Choose the right option.
string* x, y;A. x is a pointer to a string, y is a string
B. y is a pointer to a string, x is a string
C. both x and y are pointers to string types
D. y is a pointer to a string
Select an option to see the answer and solution.
What is size of generic pointer in C++ (in 32-bit platform)?
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int n = 5;
void *p = &n;
int *pi = static_cast<int*>(p);
cout << *pi << endl;
return 0;
}A. 5
B. 6
C. compile time error
D. runtime error
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char const *argv[])
{
int a = 5;
int &p = a;
cout<<p;
return 0;
}A. 5
B. Run-time error
C. Segmentation fault
D. Compile-time error
Select an option to see the answer and solution.
The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a pointer to a pointer to a integer is . . . . . . . .
A. int **fun(float**, char**)
B. int *fun(float*, char*)
C. int **fun(float*, char**)
D. int ***fun(*float, **char)
Select an option to see the answer and solution.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void print (char * a)
{
cout << a << endl;
}
int main ()
{
const char * a = "Hello world";
print(const_cast (a) );
return 0;
} A. Hello world
B. Hello
C. world
D. compile time error
Select an option to see the answer and solution.
Identify the incorrect statement.
A. Reference is the alternate name of the object
B. A reference value once defined can be reassigned
C. A reference value once defined cannot be reassigned
D. Reference is the alternate name of the variable
Select an option to see the answer and solution.
Which of the following function must use reference.
A. Assignment operator function
B. Copy Constructor
C. Destructor
D. Parameterized constructor
Select an option to see the answer and solution.