Recall & Review
beginner
What is a reference in C++?
A reference in C++ is an alias for another variable. It allows you to create a new name for an existing variable, so both names refer to the same memory location.
Click to reveal answer
beginner
How do you declare a reference variable in C++?
You declare a reference by using the & symbol after the type. For example:
int &ref = originalVariable; creates a reference named ref to originalVariable.Click to reveal answer
intermediate
Can a reference be changed to refer to another variable after initialization?
No, once a reference is initialized to a variable, it cannot be changed to refer to another variable. It always refers to the original variable it was bound to.
Click to reveal answer
beginner
What happens if you modify a reference variable?
Modifying a reference variable changes the value of the original variable it refers to, because both names point to the same memory location.
Click to reveal answer
intermediate
Why use references instead of pointers in C++?
References are safer and easier to use because they cannot be null and do not require dereferencing syntax. They provide a simpler way to alias variables without pointer complexity.
Click to reveal answer
How do you declare a reference to an int variable named
num?✗ Incorrect
Option A correctly declares a reference named
ref to the variable num.Can a reference be null in C++?
✗ Incorrect
References must always refer to a valid variable and cannot be null.
What happens if you assign a new value to a reference variable?
✗ Incorrect
Assigning a new value to a reference changes the value of the original variable it refers to.
Which symbol is used to declare a reference in C++?
✗ Incorrect
The & symbol is used to declare a reference.
Can you declare a reference without initializing it?
✗ Incorrect
References must be initialized at the time of declaration.
Explain what a reference is in C++ and how it differs from a pointer.
Think about how you use a nickname for a friend instead of their full name.
You got /4 concepts.
Describe how to declare and use a reference variable in C++ with an example.
Show how to create a new name for an existing variable and change its value.
You got /4 concepts.