0
0
C++programming~10 mins

Compilation and execution process 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 print "Hello, World!" in C++.

C++
#include <iostream>

int main() {
    std::cout << [1] << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
A"Hello, World!"
BHello, World!
Ccout << "Hello, World!"
Dstd::endl
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the double quotes around the text.
Using std::endl as the text to print.
2fill in blank
medium

Complete the code to declare an integer variable named 'count' and initialize it to 10.

C++
int [1] = 10;
Drag options to blanks, or click blank then click option'
Avalue
Bcount
Cnumber
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than 'count'.
Missing the semicolon at the end.
3fill in blank
hard

Fix the error in the code to correctly compile and run.

C++
#include <iostream>

int main() {
    int sum = 10;
    std::cout << "Sum is: " << [1] << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Asum()
Bsum;
Csum
D"sum"
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a semicolon inside the std::cout expression.
Using sum() as if it were a function.
4fill in blank
hard

Fill both blanks to create a for loop that prints numbers from 1 to 5.

C++
for (int [1] = 1; [2] <= 5; ++[1]) {
    std::cout << [1] << std::endl;
}
Drag options to blanks, or click blank then click option'
Ai
Bj
Ccount
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in initialization and condition.
Forgetting to increment the loop variable.
5fill in blank
hard

Fill all three blanks to declare a function named 'add' that takes two integers and returns their sum.

C++
int [1](int [2], int [3]) {
    return a + b;
}
Drag options to blanks, or click blank then click option'
Aadd
Ba
Cb
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameter names different from 'a' and 'b'.
Naming the function something other than 'add'.