When compiling, you get an error. What is the problem?
medium
A. Wrong return type for main
B. Missing #include <string>
C. Using std::cout incorrectly
D. Missing semicolon after std::endl
Solution
Step 1: Check syntax line by line
The line with std::cout << "Hi" << std::endl is missing a semicolon at the end.
Step 2: Identify compilation error cause
Missing semicolon causes a syntax error during compilation, stopping the process.
Final Answer:
Missing semicolon after std::endl -> Option D
Quick Check:
Semicolon missing = syntax error [OK]
Hint: Check for missing semicolons after statements [OK]
Common Mistakes:
Ignoring missing semicolon errors
Thinking #include <string> is needed here
Assuming return type is wrong
5. You have two C++ files: main.cpp and helper.cpp. You want to compile both and run the program. Which command correctly compiles and links both files into one executable named app?
hard
A. g++ main.cpp helper.cpp -o app
B. g++ main.cpp -o app helper.cpp
C. g++ -o app main.cpp; g++ helper.cpp
D. compile main.cpp helper.cpp app
Solution
Step 1: Understand compiling multiple files
To compile multiple source files together, list them all in one g++ command.
Step 2: Check command syntax for linking
g++ main.cpp helper.cpp -o app correctly lists both files and uses -o to name the executable.
Final Answer:
g++ main.cpp helper.cpp -o app -> Option A
Quick Check:
Multiple files compile = list all in one g++ command [OK]
Hint: List all source files in one g++ command to compile [OK]
Common Mistakes:
Trying to compile files separately without linking
Wrong order or syntax in command
Using unknown 'compile' command
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.