Pointers & References MCQs

5 MCQs  — Data Types MCQs

Practice Pointers & References MCQs with correct answers and explanations. These questions are from the Data Types MCQs section.

In the C++ declaration int* p, q;, what are the types of p and q?
p is int*; q is int
p is int; q is int*
Both are int
Both are int*
In C++, what is the difference between const int *p and int * const p?
The first is a pointer to const int (the data cannot change); the second is a const pointer (it cannot be redirected)
The first is a const pointer; the second is a pointer to const
They are identical
Both prevent all modification
Which statement about C++ references is correct?
A reference can be reassigned to another variable
A reference can be null
A reference must be initialized and cannot be reseated to refer to another object
A reference always occupies more memory than a pointer
Why can't a void* be dereferenced directly in C++?
Its pointed-to type is unknown, so it must first be cast to a typed pointer
It is read-only
It is 0 bytes in size
It always points to NULL
What is the main advantage of nullptr (C++11) over NULL?
It frees memory automatically
It can be dereferenced safely
It is faster
It has its own type (std::nullptr_t) and is never mistaken for an integer during overload resolution