Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a reference to an integer variable.
C++
int x = 10; int [1] y = x;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which declares a pointer instead of a reference.
Using '#' or '%' which are not valid for references.
✗ Incorrect
The symbol & is used in C++ to declare a reference variable.
2fill in blank
mediumComplete the code to declare a reference to a double variable.
C++
double pi = 3.14; double [1] refPi = pi;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which declares a pointer.
Using '&&' which is for rvalue references.
✗ Incorrect
Use & to declare a reference variable in C++.
3fill in blank
hardFix the error in the reference declaration.
C++
int a = 5; int [1] refA = &a;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which declares a pointer.
Initializing a reference with an address using '&a' instead of 'a'.
✗ Incorrect
References are declared with & and initialized with the variable itself, not its address. The code should be int &refA = a;.
4fill in blank
hardFill both blanks to declare a reference and initialize it correctly.
C++
float value = 9.8f; float [1] refValue = [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*value' which is invalid syntax.
Using the reference variable name to initialize itself.
✗ Incorrect
Use & to declare a reference and initialize it with the variable name.
5fill in blank
hardFill all three blanks to declare a constant reference to an integer.
C++
const int num = 100; const int [1] [2] = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of '&' for reference.
Initializing with the reference variable name instead of the original variable.
✗ Incorrect
To declare a constant reference, use const int &refNum = num;.