PROGRAMMING FUNDAMENTALS › C++ FUNDAMENTALS
C++ is a standardized programming language used to express instructions in source code. You write those instructions as readable text in a source file. In this example, the file is named main.cpp, and its contents describe a program that starts, does nothing visible, and finishes.
int main() {}The text in main.cpp is not something the CPU executes directly. It is a description that another program must translate into a form the computer can run. Pressing Run may make this translation and execution feel like one action, but they are separate steps underneath.
In the running example, what is main.cpp?
Checkpoints are not graded. They are here so you catch yourself before the quiz does — stuck, ask the tutor on the right.
g++ main.cpp -o first_programg++ is a compiler that reads main.cpp and checks whether its text follows C++ rules. If the source passes those checks, g++ produces an executable named first_program. That executable contains a form of the program that the operating system can start.
The command has three important pieces. main.cpp is the input source file. The option -o gives the output a name, and first_program is the requested executable name. The compiler does not produce that executable when compilation fails.
For this program, main is the entry point. When the executable starts, execution begins at main and then reaches the end of its body. The parentheses and braces are required structure around main, so this smallest source file still has the shape the compiler expects.
int main() {}There is no instruction inside the braces that displays anything, so the program has no visible output. A program can still run successfully when its only observable result is that it starts and then finishes.
Type the exact command that compiles main.cpp into an executable named first_program.
Checkpoints are not graded. They are here so you catch yourself before the quiz does — stuck, ask the tutor on the right.
g++ main.cpp -o first_program
./first_programThe first command builds the source. The second command runs the executable named first_program from the current directory. When it starts, the process enters main, reaches the closing brace, produces no visible output, and finishes successfully.
The executable is a separate result from the source file. If you edit main.cpp, the existing first_program does not change by itself. You must compile again before the edited source can affect a run. If compilation fails, no new executable is produced, so there is no newly built version to run.