0
0
C++programming~5 mins

Address and dereference operators in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe memory address of x
BThe value of x
CA copy of x
DAn error
If int* p = &x;, what does *p represent?
AThe address of x
BAn uninitialized variable
CThe pointer p itself
DThe value stored in x
Which operator is used to get the address of a variable?
A%
B*
C&
D#
What will happen if you try to dereference a null pointer?
AIt causes a runtime error or crash
BIt returns zero
CIt returns the pointer's address
DIt compiles but does nothing
How do you declare a pointer to a double variable?
Adouble ptr;
Bdouble* ptr;
Cptr double*;
D*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.