0
0
C++programming~10 mins

Reference vs pointer in C++ - Interactive Practice

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

Complete the code to declare a reference to an integer variable.

C++
int x = 10;
int& [1] = x;
Drag options to blanks, or click blank then click option'
A*p
Br
Cref
Dptr
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of & for references.
Naming the reference with invalid characters.
2fill in blank
medium

Complete the code to declare a pointer to an integer variable.

C++
int x = 20;
int [1] p = &x;
Drag options to blanks, or click blank then click option'
A*
B&
Cref
Dptr
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of * to declare a pointer.
Confusing pointer declaration with reference declaration.
3fill in blank
hard

Fix the error in the code to correctly assign a pointer to an integer variable.

C++
int x = 30;
int* p;
p = [1]x;
Drag options to blanks, or click blank then click option'
A*x
Bx
C&x
Dref x
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the variable directly instead of its address.
Using * operator incorrectly in assignment.
4fill in blank
hard

Fill both blanks to create a reference and a pointer to the same integer variable.

C++
int value = 40;
int& [1] = value;
int* [2] = &value;
Drag options to blanks, or click blank then click option'
Aref
Bptr
Cr
Dp
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid variable names.
Mixing up reference and pointer syntax.
5fill in blank
hard

Fill all three blanks to correctly dereference a pointer and assign its value to a reference.

C++
int num = 50;
int* [1] = #
int& [2] = [3];
Drag options to blanks, or click blank then click option'
Ap
Br
C*p
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the pointer variable itself to the reference instead of the dereferenced value.
Using incorrect variable names.