Recall & Review
beginner
What does the address-of operator (&) do in C++?
The address-of operator (&) gives the memory address of a variable. It tells where the variable is stored in memory.
Click to reveal answer
beginner
What is the purpose of the dereference operator (*) in C++?
The dereference operator (*) accesses the value stored at the memory address held by a pointer. It lets you read or change the value the pointer points to.
Click to reveal answer
beginner
Explain the difference between a pointer and a normal variable.
A normal variable holds a value directly. A pointer holds the memory address of another variable. You use * to get the value from the pointer's address.
Click to reveal answer
intermediate
What happens if you dereference a pointer that is not initialized?
Dereferencing an uninitialized pointer leads to undefined behavior. It may cause a crash or access random memory, which is unsafe.
Click to reveal answer
beginner
How do you declare a pointer to an integer in C++?
You declare a pointer to an integer like this: int* ptr; This means ptr can hold the address of an int variable.
Click to reveal answer
What does the expression
&x return if x is an int variable?✗ Incorrect
The & operator returns the memory address of the variable x.
If
int* p = &x;, what does *p represent?✗ Incorrect
The * operator dereferences the pointer p to get the value stored at the address it holds, which is x's value.
Which operator is used to get the address of a variable?
✗ Incorrect
The & operator is used to get the address of a variable.
What will happen if you try to dereference a null pointer?
✗ Incorrect
Dereferencing a null pointer causes a runtime error or crash because it points to no valid memory.
How do you declare a pointer to a double variable?
✗ Incorrect
The correct syntax to declare a pointer to double is: double* ptr;
Explain how the address-of (&) and dereference (*) operators work together with pointers in C++.
Think about how you get a variable's address and then use that address to get or change the variable's value.
You got /4 concepts.
Describe what happens if you try to use the dereference operator on an uninitialized or null pointer.
Consider what memory the pointer points to when it is not set properly.
You got /4 concepts.