0
0
C++programming~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 x = 10;
int * [1] = &x;
Drag options to blanks, or click blank then click option'
Ap
B*p
C&p
Dp*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' in the variable name instead of in the type declaration.
2fill in blank
medium

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

C++
int x = 20;
int *p = &x;
int y = [1]p;
Drag options to blanks, or click blank then click option'
A*
B->
C&
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' instead of '*' to access the value.
3fill in blank
hard

Fix the error in the code to correctly assign the pointer.

C++
int x = 30;
int *p;
p = [1]x;
Drag options to blanks, or click blank then click option'
Ap
Bx
C*x
D&x
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the value instead of the address to the pointer.
4fill in blank
hard

Fill both blanks to create a pointer to a pointer and access the original value.

C++
int x = 40;
int *p = &x;
int **pp = [1];
int y = [2]pp;
Drag options to blanks, or click blank then click option'
A&p
B*pp
C**pp
Dp
Attempts:
3 left
💡 Hint
Common Mistakes
Using single dereference when double is needed.
Assigning pointer value instead of its address.
5fill in blank
hard

Fill all three blanks to create a dynamic array, assign values, and access an element.

C++
int *arr = new int[[1]];
arr[0] = [2];
int first = arr[[3]];
Drag options to blanks, or click blank then click option'
A5
B10
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong index to access array element.
Assigning value to wrong index.