0
0
C++programming~10 mins

Pointer declaration in C++ - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a pointer to an integer named ptr.

C++
int [1] ptr;
Drag options to blanks, or click blank then click option'
A*
B&
C#
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of * for pointer declaration.
Forgetting the * symbol when declaring a pointer.
2fill in blank
medium

Complete the code to declare a pointer to a double named ptrDouble.

C++
double [1] ptrDouble;
Drag options to blanks, or click blank then click option'
A*
B&
C^
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Using & which is for address-of operator, not declaration.
Using symbols like ^ or ! which are invalid here.
3fill in blank
hard

Fix the error in the pointer declaration for an integer pointer named p.

C++
int [1] p;
Drag options to blanks, or click blank then click option'
A++
B*
C&&
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using & which is the address-of operator, not declaration.
Using && which is invalid syntax here.
4fill in blank
hard

Fill both blanks to declare a pointer to a character named ptrChar and initialize it to nullptr.

C++
char [1] ptrChar = [2];
Drag options to blanks, or click blank then click option'
A*
Bnullptr
CNULL
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of * for pointer declaration.
Initializing pointer with NULL instead of nullptr.
5fill in blank
hard

Fill all three blanks to declare a pointer to a float named ptrFloat, initialize it to nullptr, and then assign it the address of variable val.

C++
float [1] ptrFloat = [2];
float val = 3.14f;
ptrFloat = [3] val;
Drag options to blanks, or click blank then click option'
A*
Bnullptr
C&
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning pointer directly to val instead of its address.
Using NULL instead of nullptr for initialization.