0
0
C++programming~10 mins

Assignment operators 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 assign the value 10 to the variable x.

C++
int x [1] 10;
Drag options to blanks, or click blank then click option'
A=
B+=
C-=
D*=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' instead of '=' will add to the existing value instead of assigning.
Using '*=' or '-=' will perform multiplication or subtraction assignment, not simple assignment.
2fill in blank
medium

Complete the code to add 5 to the variable count using an assignment operator.

C++
count [1] 5;
Drag options to blanks, or click blank then click option'
A=
B*=
C-=
D+=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' will overwrite the value instead of adding.
Using '-=' or '*=' will subtract or multiply instead of adding.
3fill in blank
hard

Fix the error in the code to multiply total by 3 using an assignment operator.

C++
total [1] 3;
Drag options to blanks, or click blank then click option'
A+=
B=
C*=
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' will overwrite the value instead of multiplying.
Using '+=' or '-=' will add or subtract instead of multiplying.
4fill in blank
hard

Complete the code to subtract 4 from score and assign the result back.

C++
score [1] 4 ;
Drag options to blanks, or click blank then click option'
A-=
B+=
C;
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' will add instead of subtract.
Forgetting the semicolon causes a syntax error.
5fill in blank
hard

Fill both blanks to divide value by 2 and assign the result back, then print it.

C++
value [1] 2 ;
std::cout [2] value << std::endl;
Drag options to blanks, or click blank then click option'
A/=
B;
C<<
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '/=' will overwrite without dividing.
Forgetting semicolons causes syntax errors.
Using '=' instead of '<<' for printing causes errors.