0
0
C++programming~5 mins

Reference vs pointer in C++ - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a reference in C++?
A reference is an alias for another variable. It must be initialized when declared and cannot be changed to refer to another variable later.
Click to reveal answer
beginner
What is a pointer in C++?
A pointer is a variable that stores the memory address of another variable. It can be reassigned to point to different variables.
Click to reveal answer
intermediate
Can a reference be null in C++?
No, a reference must always refer to a valid object. It cannot be null.
Click to reveal answer
intermediate
Can a pointer be null in C++?
Yes, a pointer can hold a null value, meaning it points to no object.
Click to reveal answer
beginner
How do you access the value pointed to by a pointer?
You use the dereference operator (*) to access or modify the value the pointer points to.
Click to reveal answer
Which of the following must be initialized when declared?
AReference
BPointer
CBoth reference and pointer
DNeither
Can a pointer be reassigned to point to a different variable?
ANo, pointers are fixed
BYes, pointers can be reassigned
COnly if the pointer is const
DOnly references can be reassigned
Which can be null in C++?
APointer
BNeither
CBoth
DReference
How do you access the value a pointer points to?
AUsing the & operator
BUsing the -> operator
CUsing the * operator
DUsing the . operator
Which statement about references is true?
AReferences can be reseated to another variable
BReferences store memory addresses
CReferences can be null
DReferences are aliases and cannot be changed after initialization
Explain the main differences between a reference and a pointer in C++.
Think about initialization, nullability, and how you use them.
You got /4 concepts.
    Describe a situation where you would prefer to use a pointer over a reference.
    Consider flexibility and nullability.
    You got /4 concepts.