0
0
C++programming~10 mins

Reference declaration in C++ - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A&
B*
C#
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which declares a pointer instead of a reference.
Using '#' or '%' which are not valid for references.
2fill in blank
medium

Complete 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'
A*
B^
C&
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which declares a pointer.
Using '&&' which is for rvalue references.
3fill in blank
hard

Fix the error in the reference declaration.

C++
int a = 5;
int [1] refA = &a;
Drag options to blanks, or click blank then click option'
A#
B*
C&&
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which declares a pointer.
Initializing a reference with an address using '&a' instead of 'a'.
4fill in blank
hard

Fill 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'
A&
Bvalue
CrefValue
D*value
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*value' which is invalid syntax.
Using the reference variable name to initialize itself.
5fill in blank
hard

Fill 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'
A&
BrefNum
Cnum
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of '&' for reference.
Initializing with the reference variable name instead of the original variable.