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

4/5

Page

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

Which of the following is illegal?

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;
	int *(&q) = p;
	cout<<q;
	return 0;
}

Select an option to see the answer and solution.

Which one of the following is not a possible state for a pointer.

Select an option to see the answer and solution.

Which value can we not assign to reference?

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 f(int &x, int c) 
{
   c  = c - 1;
   if (c == 0) return 1;
   x = x + 1;
   return f(x, c) * x;
} 
int main(int argc, char const *argv[])
{
	int a = 4;
	cout<<f(a,a);
	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 &q = NULL;
	cout<<q;
	return 0;
}

Select an option to see the answer and solution.

Which reference modifier is used to define the reference variable?

Select an option to see the answer and solution.

The operator used for dereferencing or indirection is . . . . . . . .

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 &q = 5;
	cout<<q;
	return 0;
}

Select an option to see the answer and solution.

When does the void pointer can be dereferenced?

Select an option to see the answer and solution.

The constants are also called as . . . . . . . .

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 arr[] = {4, 5, 6, 7};
     int *p = (arr + 1);
     cout << *arr + 9;
     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 &p;
	int a = 5;
	&p = a;
	cout<<p;
	return 0;
}

Select an option to see the answer and solution.

Which of the following is incorrect?

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()
{
    char arr[20];
    int i;
    for(i = 0; i < 10; i++)
        *(arr + i) = 65 + i;
    *(arr + i) = '\0';
    cout << arr;
    return(0);
}

Select an option to see the answer and solution.

What are the parts of the literal constants?

Select an option to see the answer and solution.

What is the meaning of the following declaration?
int(*p[5])();

Select an option to see the answer and solution.

What will happen in the following C++ code snippet?
int a = 100, b = 200;
int *p = &a, *q = &b;
p = q;

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
#define PI 3.14159
int main ()
{
    float r = 2;
    float circle;
    circle = 2 * PI * r;
    cout << circle;
    return 0;
}

Select an option to see the answer and solution.

What is the difference between references and pointers?

Select an option to see the answer and solution.