What does a first C program teach?
The key idea
A first C program should show how source code becomes a running program and how named values produce an output. Keep the task small enough to explain every line. Here, the program totals fictional study minutes from two sessions.
C is the prerequisite for Gammal Tech's C++ course. You can use this beginner example to discuss your starting point and then develop conditions, loops, functions and arrays through further practice.
Read the complete program
#include <stdio.h>
int main(void) {
int morning = 25;
int evening = 30;
int total = morning + evening;
printf("%d\n", total);
return 0;
}
The expected output is 55 followed by a new line. The header declares the output function used here. The main function is where this small hosted C program starts. The two session variables hold whole numbers, and total receives their sum.
The return value zero indicates successful completion. It is separate from the study total. Changing the final return value to 55 would not be the correct way to print the total.
Compile it as C
Save the example as a .c file and use a trusted C compiler or the environment required by your course. A text editor saves source code; the compiler translates and checks it. Running the resulting program is a separate step.
When using GCC, a local learning command such as gcc -std=c17 -Wall -Wextra study.c -o study enables helpful warnings. Do not ignore a compiler warning simply because an executable was produced. Use the setup instructions appropriate to your operating system.
Change one thing and predict the result
Set the second session to zero. The expected total becomes 25. Set both sessions to 10 and the result becomes 20. Explain your prediction before you run the program.
| First session | Second session | Total |
|---|---|---|
| 25 | 30 | 55 |
| 25 | 0 | 25 |
| 10 | 10 | 20 |
The example uses small fixed integers, so it avoids user-input handling and large-number overflow. A real application needs rules for allowed values and checks for arithmetic limits.
Understand common beginner mistakes
An assignment stores a value; it is not the same operation as an equality comparison. Variable names must be used consistently. A missing semicolon can cause the compiler to point near the problem rather than describe your original intention.
Avoid copying a whole replacement program when one line is unclear. Explain what the line should do, then compare that intention with the code. This keeps debugging connected to understanding.
What should you practise next?
Rebuild the example from a blank file. Add a third fixed session and update the total. Then explain why a loop would become useful if the number of sessions grew.
Your milestone is not merely seeing 55 on the screen. It is knowing which values produced it, what each part of the program does and how to make a controlled change. Continue with the loops and functions guides when those foundations feel clear.
References and course details
Use these references for further study. The examples and exercises in this article are educational; consult the catalogue for course details.