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

5/5

Page

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

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
    int *p;
    void *vp;
    if (vp == p)
        cout << "equal";
    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 &fun()
{
    static int x = 10;
    return x;
}
int main()
{
    fun() = 30;
    cout << fun();
    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;
	int &q = p;
	cout<<p;
	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 func(void *Ptr);
int main()
{
    char *Str = "abcdefghij";
    func(Str);
    return 0;
}
int func(void *Ptr)
{
    cout << Ptr;
    return 0;
}

Select an option to see the answer and solution.

Which of the following statement(s) is/are correct?

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, c;
    void *p = &a;
    double b = 3.14;
    p = &b;
    c = a + b;
    cout << c << '\n' << p;
    return 0;
}

Select an option to see the answer and solution.

What are the references in C++?

Select an option to see the answer and solution.

The difference between x and 'x' is?

Select an option to see the answer and solution.

What does the following statement mean?
int (*fp)(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;
int main()
{
    int arr[] = {4, 5, 6, 7};
    int *p = (arr + 1);
    cout << arr;
    return 0;
}

Select an option to see the answer and solution.

Which of the following statement is not true about preprocessor directives?

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 &fun()
{
    int x = 10;
    return x;
}
int main()
{
    fun() = 30;
    cout << fun();
    return 0;
}

Select an option to see the answer and solution.

How a reference is different from a pointer?

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 << *p;
    return 0;
}

Select an option to see the answer and solution.

What does a reference provide?

Select an option to see the answer and solution.

Which of the following operator is used while declaring references?

Select an option to see the answer and solution.

The void pointer can point to which type of objects?

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 = 9;
    int & aref = a;
    a++;
    cout << "The value of a is " << aref;
    return 0;
}

Select an option to see the answer and solution.