Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The address-of operator
& gives the memory address of a variable.2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The dereference operator
* accesses the value stored at the memory address held by the pointer.3fill in blank
hardFix 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'
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.✗ Incorrect
To change the value of the variable pointed by
ptr, use the dereference operator *ptr.4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the asterisk in pointer declaration.
Assigning the pointer directly to the variable instead of its address.
✗ Incorrect
Declare pointer
p as int *p and assign it the address of var using &var.5fill in blank
hardFill 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'
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.
✗ Incorrect
Declare pointer as
int *, assign address with &num, and change value using dereference *ptr.