In C++, pointers and references are powerful features that provide direct access to memory and allow for highly efficient data manipulation. A pointer is a variable that stores the exact memory address of another variable, enabling dynamic memory allocation, array iteration, and pointer arithmetic. Conversely, a reference acts as a constant, underlying alias for an already existing variable, providing a safer and more intuitive syntax without requiring explicit dereferencing. Understanding the distinction between the address-of operator (&) and the dereference operator (*) is a critical milestone for C++ programmers. Mastery of these concepts is essential for optimizing application performance, managing heap memory, and efficiently passing large objects to functions.
C++ Pointers and References - MCQs
1 min read
Correct Answer: a) A variable that stores the memory address of another variable
Explanation:
A pointer is a variable whose value is the memory address of another variable.
Correct Answer: b) &
Explanation:
The address-of operator (&) is used to obtain the memory address of a variable.
Correct Answer: c) *
Explanation:
The dereference operator (*) is used to access the value at the memory address stored in a pointer.
Correct Answer: c) 8 bytes
Explanation:
On a 64-bit system, memory addresses are 64 bits (8 bytes) long, so standard pointers are typically 8 bytes in size.
Correct Answer: c) Wild pointer
Explanation:
A wild pointer is a pointer that has not been initialized and points to an arbitrary memory location, which can lead to undefined behavior.
Correct Answer: b) Dangling pointer
Explanation:
A dangling pointer points to memory that has already been deallocated or freed, leading to undefined behavior if accessed.
Correct Answer: c) nullptr
Explanation:
The nullptr keyword was introduced in C++11 as a type-safe alternative to the macro NULL for representing null pointers.
Correct Answer: c) std::nullptr_t
Explanation:
The type of nullptr is std::nullptr_t, which is implicitly convertible to any pointer type or pointer-to-member type.
Correct Answer: c) It becomes a dangling pointer
Explanation:
After a pointer is deleted, it still holds the old memory address, making it a dangling pointer until it is explicitly set to nullptr.
Correct Answer: c) int *ptr;
Explanation:
The asterisk (*) is used in the declaration to indicate that the variable is a pointer to the specified type.
Correct Answer: b) ptr is a pointer to a constant integer
Explanation:
In `const int* ptr`, the const applies to the int, meaning the integer value being pointed to cannot be changed through this pointer, but the pointer itself can be reassigned.
Correct Answer: a) ptr is a constant pointer to an integer
Explanation:
In `int* const ptr`, the const applies to the pointer itself, meaning the address stored in ptr cannot be changed, but the integer value it points to can be modified.
Correct Answer: c) ptr is a constant pointer to a constant integer
Explanation:
Both the pointer and the value it points to are constant. Neither the address stored in ptr nor the integer value can be changed.
Correct Answer: b) No
Explanation:
The const qualifier on the int means the value being pointed to is read-only through this pointer.
Correct Answer: a) Yes
Explanation:
The pointer itself is not constant, so it can be reassigned to point to a different memory address.
Correct Answer: a) Yes
Explanation:
The integer value being pointed to is not constant, so it can be modified through the pointer.
Correct Answer: b) No
Explanation:
The const qualifier applies to the pointer itself, meaning the memory address it holds cannot be changed.
Correct Answer: a) A pointer that has not been initialized
Explanation:
A wild pointer is an uninitialized pointer that points to an arbitrary memory location, which can cause unpredictable behavior if dereferenced.
Correct Answer: b) A pointer that points to freed or deallocated memory
Explanation:
A dangling pointer occurs when a pointer continues to hold the address of memory that has been deallocated, leading to undefined behavior if accessed.
Correct Answer: c) Undefined behavior, typically a crash
Explanation:
Dereferencing a null pointer results in undefined behavior, which usually causes a segmentation fault or access violation, crashing the program.
Correct Answer: b) 1004
Explanation:
Pointer arithmetic scales by the size of the pointed-to type. Adding 1 to an int pointer adds the size of an int (4 bytes), resulting in 1004.
Correct Answer: b) The number of elements between them
Explanation:
When subtracting two pointers to the same array, the result is the number of elements between them, not the byte difference.
Correct Answer: b) No
Explanation:
Adding two pointers is not a valid operation in C++ because the result would not represent a meaningful memory address.
Correct Answer: b) 2003
Explanation:
Since a char is 1 byte, adding 3 to a char pointer advances the address by 3 bytes, resulting in 2003.
Correct Answer: d) ptr1 + ptr2
Explanation:
You can add an integer to a pointer or subtract two pointers, but adding two pointers together is not allowed in C++.
Correct Answer: a) Dereferences a pointer and accesses a member
Explanation:
The arrow operator (->) is used to access members of a class or struct through a pointer to that object.
Correct Answer: b) (*ptr).member
Explanation:
The expression `ptr->member` is syntactic sugar for `(*ptr).member`, which first dereferences the pointer and then accesses the member.
Correct Answer: b) No, it results in undefined behavior
Explanation:
Relational comparisons between pointers are only valid if they point to elements of the same array or one past the end; otherwise, it is undefined behavior.
Correct Answer: a) 0
Explanation:
Subtracting a pointer from itself yields 0, representing zero elements between the same address.
Correct Answer: b) 3992
Explanation:
Subtracting 1 from a double pointer subtracts the size of a double (8 bytes), resulting in 3992.
Correct Answer: b) It decays to a pointer to its first element
Explanation:
In most expressions, an array name implicitly decays (converts) to a pointer to its first element.
Correct Answer: b) No, but they are closely related
Explanation:
Arrays and pointers are not the same; arrays are fixed-size contiguous blocks of memory, while pointers are variables that store addresses, though arrays often decay to pointers.
Correct Answer: c) 40
Explanation:
The sizeof operator on an array returns the total size in bytes, which is 10 elements * 4 bytes = 40 bytes.
Correct Answer: b) 8
Explanation:
On a 64-bit system, pointers are 8 bytes in size, regardless of the type they point to.
Correct Answer: b) int (*ptr)[5];
Explanation:
The parentheses are necessary to declare a pointer to an array. Without them, it would declare an array of pointers.
Correct Answer: b) int *ptr[5];
Explanation:
This declares an array of 5 elements, where each element is a pointer to an integer.
Correct Answer: a) Yes
Explanation:
Since the array name decays to a pointer to its first element in expressions, you can perform pointer arithmetic on it.
Correct Answer: b) They are equivalent
Explanation:
The subscript operator [] is defined such that `arr[i]` is exactly equivalent to `*(arr + i)`.
Correct Answer: b) No
Explanation:
An array name is a constant pointer to its first element; it cannot be reassigned to point to a different memory location.
Correct Answer: b) Pass by reference
Explanation:
Passing an array by reference (e.g., `void func(int (&arr)[10])`) prevents it from decaying to a pointer and preserves its size information.
Correct Answer: b) A generic pointer that can point to any data type
Explanation:
A void pointer is a generic pointer type that can hold the address of any data type, but it cannot be dereferenced directly.
Correct Answer: b) No
Explanation:
A void pointer has no associated type, so the compiler does not know how many bytes to read or how to interpret the data; it must be cast first.
Correct Answer: c) *(int*)ptr
Explanation:
You must first cast the void pointer to an int pointer, and then dereference it to access the integer value.
Correct Answer: b) No, not in standard C++
Explanation:
Standard C++ does not allow pointer arithmetic on void pointers because the size of the pointed-to type is unknown. (GCC allows it as an extension, treating void as size 1).
Correct Answer: b) To write generic functions and data structures that can handle any data type
Explanation:
Void pointers are commonly used in C-style generic programming, such as in the parameters of qsort or malloc, to handle data of any type.
Correct Answer: b) static_cast<int*>(ptr)
Explanation:
static_cast is the appropriate C++ cast for converting a void pointer to a typed pointer, as it performs compile-time type checking.
Correct Answer: b) No
Explanation:
A void pointer can point to data objects, but it cannot point to member functions because member functions have a different representation and may require a 'this' pointer.
Correct Answer: c) They are the same size
Explanation:
All data pointers on a given architecture typically have the same size, regardless of the type they point to.
Correct Answer: b) No
Explanation:
C++ requires an explicit cast to convert a void pointer to a typed pointer to ensure type safety.
Correct Answer: a) Yes
Explanation:
In C, void pointers can be implicitly assigned to and from any other object pointer type without an explicit cast.
Correct Answer: b) double (*func)(int);
Explanation:
The parentheses around *func are necessary to indicate that func is a pointer to a function, rather than a function returning a pointer.
Correct Answer: c) funcPtr(args)
Explanation:
Function pointers can be called using the same syntax as regular function names, without needing to explicitly dereference them.
Correct Answer: b) To implement callbacks and tables of functions
Explanation:
Function pointers allow functions to be passed as arguments, stored in arrays, and called dynamically, enabling callbacks and jump tables.
Correct Answer: a) Yes
Explanation:
You can create an array of function pointers, provided all functions in the array have the exact same signature.
Correct Answer: a) Pointer to a function taking int and returning void
Explanation:
The declaration specifies that fp is a pointer to a function that accepts an int parameter and returns void.
Correct Answer: a) Yes
Explanation:
Function pointers can be initialized to or assigned nullptr, and should be checked before calling to avoid undefined behavior.
Correct Answer: a) By passing its name or a function pointer
Explanation:
You can pass a function by simply using its name (which decays to a pointer) or by explicitly passing a function pointer.
Correct Answer: b) A function passed as an argument to another function and called later
Explanation:
A callback is a function passed as an argument to another function, which is then invoked inside the outer function to complete a routine or action.
Correct Answer: b) No, the function name decays to a pointer
Explanation:
Just like arrays, function names implicitly decay to function pointers in expressions, so the & operator is optional.
Correct Answer: b) No, but you can overload the function itself
Explanation:
You cannot overload the pointer itself, but if the functions being pointed to are overloaded, you must cast to the specific function signature to resolve the ambiguity.
Correct Answer: b) An alias for an existing variable
Explanation:
A reference is an alternative name (alias) for an existing variable; once initialized, it acts exactly like the original variable.
Correct Answer: b) &
Explanation:
The ampersand (&) is used in the declaration to indicate that the variable is a reference to the specified type.
Correct Answer: a) Yes
Explanation:
References must be initialized upon declaration because they are aliases and cannot exist without referring to an actual object.
Correct Answer: b) No
Explanation:
Once a reference is bound to an object, it cannot be rebound to refer to a different object; any assignment modifies the original object.
Correct Answer: b) No
Explanation:
References must always refer to a valid object; there is no such thing as a null reference in standard C++.
Correct Answer: c) They are typically the same size in implementation
Explanation:
Although references are conceptually aliases, compilers typically implement them using pointers under the hood, making their size equal to a pointer.
Correct Answer: b) A reference to a constant variable
Explanation:
A const reference (e.g., `const int&`) is a reference through which the referred object cannot be modified.
Correct Answer: b) No
Explanation:
The const qualifier prevents modification of the referred object through that specific reference.
Correct Answer: b) No
Explanation:
Standard C++ does not allow non-const lvalue references to bind to temporary objects (rvalues) to prevent accidental modification of soon-to-be-destroyed data.
Correct Answer: a) Yes, and it extends the temporary's lifetime
Explanation:
A const lvalue reference can bind to a temporary, and the C++ standard guarantees that the temporary's lifetime is extended to match the lifetime of the reference.
Correct Answer: a) Pointers can be null, references cannot
Explanation:
Pointers can hold a null value, but references must always be bound to a valid object and cannot be null.
Correct Answer: b) When the argument should not be null and you want cleaner syntax
Explanation:
References provide cleaner syntax (no dereferencing needed) and guarantee the argument is not null, making them ideal when nullability is not required.
Correct Answer: b) A reference that can bind to temporary objects (rvalues)
Explanation:
Rvalue references (declared with &&) are designed to bind to temporary objects, enabling move semantics and perfect forwarding.
Correct Answer: b) &&
Explanation:
The double ampersand (&&) is used to declare an rvalue reference in C++11 and later.
Correct Answer: b) Only rvalues (temporaries)
Explanation:
By default, an rvalue reference can only bind to rvalues (temporary objects or values explicitly cast with std::move), not to named lvalues.
Correct Answer: b) To implement move semantics and perfect forwarding
Explanation:
Rvalue references were introduced primarily to support move semantics (efficiently transferring resources from temporaries) and perfect forwarding in templates.
Correct Answer: b) Rules that determine the resulting reference type when combining references in templates
Explanation:
Reference collapsing is a set of rules in C++ that dictate how nested references (e.g., in template type deduction) are simplified to a single reference type.
Correct Answer: b) int&
Explanation:
According to reference collapsing rules, if either reference is an lvalue reference (&), the result is an lvalue reference (&).
Correct Answer: a) int&&
Explanation:
If both references are rvalue references (&&), the collapsed result remains an rvalue reference (&&).
Correct Answer: b) const int&
Explanation:
Since T is an lvalue reference, the collapsed result is an lvalue reference, preserving the const qualifier.
Correct Answer: b) <memory>
Explanation:
The header contains the definitions for standard smart pointers like std::unique_ptr, std::shared_ptr, and std::weak_ptr.
Correct Answer: b) They automatically manage memory and prevent leaks
Explanation:
Smart pointers use RAII to automatically deallocate memory when they go out of scope, preventing memory leaks.
Correct Answer: c) std::unique_ptr
Explanation:
std::unique_ptr enforces exclusive ownership, meaning only one unique_ptr can own the resource at any given time.
Correct Answer: b) std::shared_ptr
Explanation:
std::shared_ptr allows multiple pointers to share ownership of a resource using reference counting.
Correct Answer: c) std::weak_ptr
Explanation:
std::weak_ptr holds a non-owning reference to a resource managed by a shared_ptr, which prevents reference cycles that can cause memory leaks.
Correct Answer: b) To create a unique_ptr safely
Explanation:
std::make_unique is a factory function that safely creates a std::unique_ptr, ensuring exception safety and avoiding code duplication.
Correct Answer: b) To create a shared_ptr safely and efficiently
Explanation:
std::make_shared creates a shared_ptr and allocates the object and control block in a single memory allocation, improving performance and safety.
Correct Answer: b) No, it can only be moved
Explanation:
std::unique_ptr disables its copy constructor and copy assignment operator to enforce exclusive ownership; it can only be transferred via move semantics.
Correct Answer: a) Yes
Explanation:
std::shared_ptr can be copied; each copy increments the reference count, sharing ownership of the managed resource.
Correct Answer: c) It is deleted
Explanation:
When a std::unique_ptr goes out of scope, its destructor is called, which automatically deletes the managed object and frees the memory.
Correct Answer: b) A pointer that stores the offset of a member within a class
Explanation:
A pointer to a non-static class member does not store an absolute address, but rather the offset of that member within the class layout.
Correct Answer: b) int MyClass::*ptr;
Explanation:
The syntax for a pointer to a data member is `Type ClassName::*pointerName`.
Correct Answer: a) obj.*ptr
Explanation:
The .* operator is used to access a member of an object using a pointer to that member.
Correct Answer: a) To access a member via a pointer to member using an object
Explanation:
The .* operator combines an object and a pointer-to-member to access the specific member of that object.
Correct Answer: b) To access a member via a pointer to member using a pointer to an object
Explanation:
The ->* operator is used when you have a pointer to an object and a pointer to a member, allowing you to access the member through the object pointer.
Correct Answer: a) MyClass* const
Explanation:
In a non-const member function, the `this` pointer is a constant pointer to a non-constant object, meaning the pointer itself cannot be changed, but the object can be.
Correct Answer: b) const MyClass* const
Explanation:
In a const member function, the `this` pointer is a constant pointer to a constant object, meaning neither the pointer nor the object can be modified.
Correct Answer: b) It returns the address of the object the reference refers to
Explanation:
Applying the address-of operator to a reference yields the address of the underlying object it is bound to, not the reference itself.
Correct Answer: b) The address of the object being referenced
Explanation:
Since a reference is an alias, taking its address is identical to taking the address of the original variable it refers to.
Correct Answer: b) The size of the object being referenced
Explanation:
The sizeof operator applied to a reference returns the size of the underlying object type, not the size of the reference implementation.
Related Posts
NewNew
New
No Image
C++ Inheritance and Polymorphism - MCQs
1. What is a pointer in C++? a) A variable that stores the memory address of another variable b) A…
October 19, 2026By MCQs Generator

C++ Strings MCQs
In C++, strings are handled in two primary ways: traditional C-style strings (null-terminated character arrays) and the modern std::string class…
October 20, 2026By MCQs Generator
No Image
C++ Control Flow / If-Else MCQs Conditional Statements
1. What is a pointer in C++? a) A variable that stores the memory address of another variable b) A…
October 20, 2026By MCQs Generator








