DSA SheetLesson · no judge

PROGRAMMING FUNDAMENTALSC++ FUNDAMENTALS

What C++ Is and How Your First Program Runs

Reading · 6 minQuiz · 5 questions2 code drills · run onlyGenerated by gpt-5.6-luna · Aug 14

C++ is a language for describing a program, not the program that the CPU runs

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.

CPPThe complete source text for the running example.
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.

CHECKPOINT 1Not answered

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.

A compiler must translate main.cpp before the computer can run it

TEXTThe command that builds the source file into first_program.
g++ main.cpp -o first_program

g++ 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.

The path from main.cpp to the running first_program executableFrom left to right, main.cpp contains `int main() {}`. The command `g++ main.cpp -o first_program` sends that source through the g++ compiler, which produces the executable first_program after successful compilation. The command `./first_program` starts that executable as a running process. The process enters main, shows no output, and finishes.int main() {}g++ compilertranslation + rule-checkingfirst_programexecutablerunning processstarts at mainno visible outputfinishes successfullyg++ main.cpp -o first_programsuccessful compile./first_program
Source is compiled into an executable before it can run.

The function named main marks where this program starts

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.

CPPThe smallest source used throughout this lesson.
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.

CHECKPOINT 2Not answered

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.

Building and running are separate actions

TEXTBuild first, then start the executable.
g++ main.cpp -o first_program
./first_program

The 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.

Next part · Quiz