0
0
C++programming~10 mins

Address and dereference operators 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 get the address of variable num.

C++
int num = 10;
int* ptr = [1]num;
Drag options to blanks, or click blank then click option'
A&
B*
C#
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dereference operator * instead of the address-of operator &.
Using symbols like # or % which are not related to pointers.
2fill in blank
medium

Complete the code to access the value pointed to by ptr.

C++
int num = 20;
int* ptr = #
int value = [1]ptr;
Drag options to blanks, or click blank then click option'
A&
B%
C*
D->
Attempts:
3 left
💡 Hint
Common Mistakes
Using the address-of operator & instead of dereference operator *.
Using the arrow operator -> which is for pointers to structs or classes.
3fill in blank
hard

Fix the error in the code to correctly assign the value 50 to the variable pointed to by ptr.

C++
int num = 0;
int* ptr = #
[1]ptr = 50;
Drag options to blanks, or click blank then click option'
A*ptr
B&ptr
Cptr
Dptr*
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning directly to the pointer variable instead of the value it points to.
Using incorrect syntax like ptr* or &ptr.
4fill in blank
hard

Fill both blanks to create a pointer ptr that points to num and then access its value.

C++
int num = 100;
int* ptr = [1]num;
int val = [2]ptr;
Drag options to blanks, or click blank then click option'
A&
B*
C->
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the operators in the blanks.
Using the arrow operator -> which is not for simple pointers.
5fill in blank
hard

Fill all three blanks to declare an integer num, a pointer ptr to num, and assign the value 75 to num using the pointer.

C++
int [1];
int* [2] = &[3];
*ptr = 75;
Drag options to blanks, or click blank then click option'
Anum
Bptr
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the variable and pointer inconsistently.
Not using the address-of operator & in the pointer initialization.