Recall & Review
beginner
What is a pointer in C++?
A pointer is a variable that stores the memory address of another variable.
Click to reveal answer
beginner
How do you declare a pointer to an integer variable?
You declare it using the syntax:
int* ptr; where ptr is the pointer variable.Click to reveal answer
beginner
What does the * operator do when used with a pointer?
It dereferences the pointer, meaning it accesses the value stored at the memory address the pointer holds.
Click to reveal answer
intermediate
Explain the relationship between a pointer and the variable it points to.
A pointer holds the address of a variable. Changing the value through the pointer changes the original variable's value because they refer to the same memory location.
Click to reveal answer
intermediate
What happens if you change the pointer's value itself?
Changing the pointer's value changes the memory address it points to, so it will point to a different variable or memory location.
Click to reveal answer
What does the following code print?<br>
int x = 10;<br>int* p = &x;<br>std::cout << *p;
✗ Incorrect
The pointer p stores the address of x. Using *p accesses the value of x, which is 10.
Which operator is used to get the address of a variable?
✗ Incorrect
The & operator returns the memory address of a variable.
If
int* p; is uninitialized, what happens if you try to dereference it?✗ Incorrect
Dereferencing an uninitialized pointer leads to undefined behavior and can crash the program.
What does the pointer store?
✗ Incorrect
Pointers store memory addresses of variables.
How do you change the value of a variable using a pointer?
✗ Incorrect
Using *pointer = new_value changes the value at the memory address the pointer points to.
Explain in your own words how a pointer relates to the variable it points to.
Think about how a pointer is like a remote control to a TV.
You got /3 concepts.
Describe what happens when you change the pointer's value versus when you change the value it points to.
Consider the pointer as an address label and the variable as the house at that address.
You got /3 concepts.