0
0
C++programming~10 mins

Increment and decrement 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 increment the variable count by 1.

C++
int count = 5;
count[1];
Drag options to blanks, or click blank then click option'
A++
B--
C+=
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using the decrement operator -- instead of increment.
Using += without specifying the amount.
2fill in blank
medium

Complete the code to decrement the variable value by 1.

C++
int value = 10;
value[1];
Drag options to blanks, or click blank then click option'
A--
B++
C+=
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using the increment operator ++ instead of decrement.
Using -= without specifying the amount.
3fill in blank
hard

Fix the error in the code to correctly increment num.

C++
int num = 7;
num = num[1];
Drag options to blanks, or click blank then click option'
A++
B- 1
C--
D+ 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using ++ after assignment operator.
Using decrement operators instead of increment.
4fill in blank
hard

Fill both blanks to create a map of numbers to their squares using increment in the loop.

C++
std::map<int, int> squares;
for (int i = 1; i [1] 5; i[2]) {
    squares[i] = i * i;
}
Drag options to blanks, or click blank then click option'
A<=
B<
C++
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Using i <= 5 causes the loop to run one extra time.
Using decrement operator -- in the loop.
5fill in blank
hard

Fill all three blanks to create a map of uppercase letters to their ASCII codes, incrementing the letter.

C++
std::map<char, int> ascii_map;
for (char ch = 'A'; ch [1] 'Z'; ch[2]) {
    ascii_map[[3]] = static_cast<int>(ch);
}
Drag options to blanks, or click blank then click option'
A<=
B++
Cch
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Using < code < 'Z' > causes 'Z' to be excluded.
Using decrement operator -- instead of increment.
Using wrong variable as map key.