Vidyalelo
C++ Programming · all questions

Pointers and References in C++
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

98

Questions

2/5

Page

Pick an option on a question to see the right answer and solution.

What is the correct way to pass a pointer to a function in C++?

Select an option to see the answer and solution.

What is a memory leak in C++?

Select an option to see the answer and solution.

What is the purpose of the 'delete' keyword in C++?

Select an option to see the answer and solution.

What does the 'nullptr' keyword signify when used as a pointer value in C++?

Select an option to see the answer and solution.

What is a pointer arithmetic in C++?

Select an option to see the answer and solution.

What is the purpose of the 'this' pointer in C++?

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++?

Select an option to see the answer and solution.

What does the 'sizeof' operator return when used with a pointer variable in C++?

Select an option to see the answer and solution.

What is the purpose of the 'const' keyword in a pointer declaration in C++?

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++?

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?

Select an option to see the answer and solution.

Choose the right option.
string* x, y;

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;
}

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;
}

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 . . . . . . . .

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;
}

Select an option to see the answer and solution.

Identify the incorrect statement.

Select an option to see the answer and solution.

Which of the following function must use reference.

Select an option to see the answer and solution.