0
0
Cprogramming~10 mins

Writing first C program - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Writing first C program
Start
Include stdio.h
Define main() function
Execute printf statement
Return 0
End program
This flow shows the steps of a simple C program: include library, define main, print message, return success, and end.
Execution Sample
C
#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}
This program prints 'Hello, world!' to the screen and then ends.
Execution Table
StepCode LineActionOutputNext Step
1#include <stdio.h>Include standard input/output library2
2int main() {Start main function3
3printf("Hello, world!\n");Print text to screenHello, world!4
4return 0;Return 0 to signal success5
5}End main functionProgram ends
💡 Program ends after main returns 0, signaling successful completion.
Variable Tracker
VariableStartAfter printfFinal
None---
Key Moments - 3 Insights
Why do we include <stdio.h> at the start?
Because printf is defined in stdio.h, including it allows us to use printf without errors, as shown in step 1 of the execution_table.
What does 'return 0;' mean in main()?
It tells the system the program finished successfully, as seen in step 4 where return 0 ends the program.
Why is there a \n inside the printf string?
The \n adds a new line after printing, so the output looks clean, demonstrated in step 3 where 'Hello, world!' is printed with a line break.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what does step 3 do?
AEnds the program
BPrints 'Hello, world!' to the screen
CIncludes the stdio.h library
DReturns 0 to the system
💡 Hint
Check the 'Action' and 'Output' columns in step 3 of the execution_table.
At which step does the program signal successful completion?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look for 'Return 0' in the 'Code Line' and 'Action' columns.
If we remove '#include <stdio.h>', what will happen?
ACompiler will give an error about printf
BProgram will print 'Hello, world!' normally
CProgram will return 1 instead of 0
DProgram will run but output nothing
💡 Hint
Recall why stdio.h is included from the key_moments about step 1.
Concept Snapshot
#include <stdio.h>  // Include input/output library
int main() {          // Main function start
  printf("Hello, world!\n");  // Print message
  return 0;           // End program successfully
}
Full Transcript
This simple C program starts by including the standard input/output library stdio.h so we can use printf. The main function is where the program begins running. Inside main, printf prints the message 'Hello, world!' followed by a new line. Then return 0 signals the program finished successfully. The program ends after main returns. Each step is shown in the execution table, helping beginners see how the program runs line by line.