0
0
C++programming~5 mins

Pointer declaration in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a pointer in C++?
A pointer is a variable that stores the memory address of another variable. It 'points' to the location where data is stored.
Click to reveal answer
beginner
How do you declare a pointer to an integer in C++?
You declare it using the syntax: int* ptr; Here, ptr is a pointer to an integer.
Click to reveal answer
beginner
What does the asterisk (*) mean in a pointer declaration?
The asterisk (*) indicates that the variable is a pointer type, meaning it holds the address of a variable of the specified type.
Click to reveal answer
beginner
Explain the difference between int* ptr; and int *ptr;.
Both are the same. The position of the asterisk (*) does not change the meaning. It just shows ptr is a pointer to an int.
Click to reveal answer
intermediate
What happens if you declare a pointer but do not initialize it?
The pointer will contain a garbage (random) address. Using it without initialization can cause errors or crashes.
Click to reveal answer
Which of the following declares a pointer to a float?
Afloat* ptr;
Bfloat ptr*;
Cptr* float;
Dfloat &ptr;
What does the pointer variable store?
AThe size of a variable
BThe value of another variable
CThe memory address of another variable
DThe type of a variable
How do you declare a pointer to an integer named p?
Aint p*;
Bint &p;
Cint p;
Dint* p;
What is the value of an uninitialized pointer?
ARandom garbage address
BNULL
CThe address of the pointer itself
D0
Which symbol is used to declare a pointer?
A&
B*
C#
D$
Describe how to declare a pointer to a variable in C++ and explain what it stores.
Think about how you tell the computer to remember where something is stored.
You got /3 concepts.
    What risks are there if you use a pointer without initializing it first?
    Consider what happens if you try to use a random address.
    You got /3 concepts.