0
0
Cprogramming~10 mins

Why pointers are needed in C - Test Your Understanding

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.

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 * to declare a pointer.
Forgetting the * symbol when declaring a pointer.
2fill in blank
medium

Complete the code to assign the address of variable 'a' to pointer 'ptr'.

C
int a = 10;
int *ptr;
ptr = [1]a;
Drag options to blanks, or click blank then click option'
A%
B*
C#
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of & to get the address.
Assigning the variable value instead of its address.
3fill in blank
hard

Fix the error in the code to correctly print the value pointed by 'ptr'.

C
int a = 5;
int *ptr = &a;
printf("%d", [1]);
Drag options to blanks, or click blank then click option'
A*ptr
Bptr
C&ptr
D&&ptr
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the pointer address instead of the value.
Using &ptr which gives the address of the pointer itself.
4fill in blank
hard

Fill both blanks to create a pointer to an integer and assign it the address of variable 'num'.

C
int num = 20;
[1] ptr;
ptr = [2]num;
Drag options to blanks, or click blank then click option'
Aint *
Bint
C&
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Declaring pointer without *.
Assigning value instead of address.
5fill in blank
hard

Fill all three blanks to create a pointer, assign it the address of 'val', and print the value using the pointer.

C
int val = 30;
[1] ptr;
ptr = [2]val;
printf("%d", [3]ptr);
Drag options to blanks, or click blank then click option'
Aint *
B&
C*
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting * in declaration.
Assigning value instead of address.
Printing pointer address instead of value.