0
0
C++programming~20 mins

Compilation and execution process in C++ - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Compilation and Execution
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple C++ program with compilation steps
What is the output of this C++ program when compiled and run?
C++
#include <iostream>
int main() {
    int x = 5;
    int y = 10;
    std::cout << "Sum: " << (x + y) << std::endl;
    return 0;
}
ASum: 510
BSum: 15
CCompilation error
DRuntime error
Attempts:
2 left
💡 Hint
Remember that + operator adds integers, not concatenates strings.
🧠 Conceptual
intermediate
1:30remaining
Identify the compilation stage that converts source code to machine code
Which stage in the C++ compilation process converts the source code into machine code?
APreprocessing
BLinking
CCompilation
DExecution
Attempts:
2 left
💡 Hint
Think about when the code is translated into instructions the computer understands.
Predict Output
advanced
2:30remaining
Output of a program with multiple source files and linking
Given two source files compiled and linked, what is the output when running the program?
C++
// file1.cpp
#include <iostream>
void greet();
int main() {
    greet();
    return 0;
}

// file2.cpp
#include <iostream>
void greet() {
    std::cout << "Hello from linked file!" << std::endl;
}
AHello from linked file!
BCompilation error: greet undefined
CRuntime error: undefined reference
DNo output
Attempts:
2 left
💡 Hint
Both files must be compiled and linked together to find greet.
Predict Output
advanced
2:00remaining
What error occurs if a function is declared but not defined?
What error will the compiler or linker produce for this code?
C++
#include <iostream>
void foo();
int main() {
    foo();
    return 0;
}
ALinker error: undefined reference to foo
BProgram runs with no output
CRuntime error: segmentation fault
DCompilation error: foo not declared
Attempts:
2 left
💡 Hint
Declaration exists but no function body is provided.
🧠 Conceptual
expert
2:30remaining
Order the stages of C++ program compilation and execution
Select the correct order of stages when compiling and running a C++ program.
A1,3,2,4
B2,1,3,4
C3,2,1,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Think about the order from source code to running program.