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

3/5

Page

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

How are the constants declared?

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 = a;
	cout<<p<<endl;
	cout<<q<<endl;
	return 0;
}

Select an option to see the answer and solution.

How to declare a wide character in the string literal?

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 = a;
	cout<<*p<<endl;
	cout<<*q<<endl;
	return 0;
}

Select an option to see the answer and solution.

Pick the correct statement about references.

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 numbers[5];
    int * p;
    p = numbers;  *p = 10;
    p++;  *p = 20;
    p = &numbers[2];  *p = 30;
    p = numbers + 3;  *p = 40;
    p = numbers;  *(p + 4) = 50;
    for (int n = 0; n < 5; n++)
       cout << numbers[n] << ",";
    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;
 
void func(const int &a)
{
	int temp = 10;
	a = temp;
	cout<<a;
}
 
int main(int argc, char const *argv[])
{
	int a = 5;
	func(a);
	return 0;
}

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 i;
    char c;
    void *data;
    i = 2;
    c = 'd';
    data = &i;
    cout << "the data points to the integer value" << data;
    data = &c;
    cout << "the data now points to the character" << data;
    return 0;
}

Select an option to see the answer and solution.

Regarding the following statement which of the statements is true?
const int a = 100;

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 *ptr;
    char Str[] = "abcdefg";
    ptr = Str;
    ptr += 5;
    cout << ptr;
    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 &q = a;
	cout<<&a<<endl;
	cout<<&q<<endl;
	return 0;
}

Select an option to see the answer and solution.

The pointer can point to any variable that is not declared with which of these?

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 swap(int &a, int &b);
int main()
{
    int a = 5, b = 10;
    swap(a, b);
    cout << "In main " << a << b;
    return 0;
}
void swap(int &a, int &b)
{
    int temp;
    temp = a;
    a = b;
    b = temp;
    cout << "In swap " << a << b;
}

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 a = 5, b = 10, c = 15;
    int *arr[ ] = {&a, &b, &c};
    cout << arr[1];
    return 0;
}

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 x = 10;
   int& ref = x;
   ref = 20;
   cout << x << endl ;
   x = 30;
   cout << ref << endl;
   return 0;
}

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 a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
    cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
    return 0;
}

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 i;
    const char *arr[] = {"C", "C++", "Java", "VBA"};
    const char *(*ptr)[4] = &arr;
    cout << ++(*ptr)[2];
    return 0;
}

Select an option to see the answer and solution.

Pick the correct statement about references in C++.

Select an option to see the answer and solution.

A void pointer cannot point to which of these?

Select an option to see the answer and solution.

Identify the correct sentence regarding inequality between reference and pointer.

Select an option to see the answer and solution.