0
0
Cprogramming~10 mins

Address and dereference operators - 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 address operators.
2fill in blank
medium

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

C
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 accessing members of a struct pointer.
3fill in blank
hard

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

C
int num = 10;
int *ptr = #
[1]ptr = 20;
Drag options to blanks, or click blank then click option'
Aptr*
Bptr
C*
D&ptr
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 p that points to var and then access its value.

C
int var = 5;
int [1] p = [2]var;
int val = *p;
Drag options to blanks, or click blank then click option'
A*
B&
Cint
Dptr
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the asterisk in pointer declaration.
Assigning the pointer directly to the variable instead of its address.
5fill in blank
hard

Fill all three blanks to declare a pointer ptr, assign it the address of num, and then change the value of num to 100 using the pointer.

C
int num = 50;
[1] ptr = [2]num;
[3]ptr = 100;
Drag options to blanks, or click blank then click option'
Aint *
B&
C*
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Missing the asterisk in pointer declaration.
Assigning pointer directly to variable instead of its address.
Trying to assign value to pointer variable instead of dereferenced pointer.