C is a language that, once you learn it, gives you a clear picture of how a computer works under the hood. In this tutorial we will look at four fundamentals of C — variables, conditions, loops, and functions — with examples.
1. Variables and data types
A variable is a named box in memory where we store a value. In C, every variable has a specific type:
int age = 20; // integer
float gpa = 3.85; // decimal number
char grade = 'A'; // a single character
printf("Age: %d, GPA: %.2f\n", age, gpa);
Here %d prints an integer and %.2f prints a float to two decimal places.
2. Conditions: making decisions
A program has to make different decisions depending on the situation. That is the job of if-else:
int marks = 78;
if (marks >= 80) {
printf("Grade: A+\n");
} else if (marks >= 70) {
printf("Grade: A\n");
} else {
printf("Needs more effort\n");
}
The program checks the conditions from top to bottom and runs only the block whose condition is true first.

3. Loops: doing the same thing repeatedly
Loops are used to do the same task over and over. Here is an example that prints the numbers 1 through 5:
for (int i = 1; i <= 5; i++) {
printf("%d ", i);
}
// Output: 1 2 3 4 5
A for loop has three parts — the starting value, the condition to keep going, and the change each time. When you do not know the count in advance, a while loop is more useful.
4. Functions: breaking up your code
Instead of writing the same code repeatedly, we put it in a function and call it as needed:
int sum(int a, int b) {
return a + b;
}
int main() {
int result = sum(7, 8);
printf("Sum: %d\n", result); // Sum: 15
return 0;
}
Functions make code clean, reusable, and easy to test.
Practice on your own
- Write a program that checks whether a number is even or odd.
- Find the sum of the numbers from 1 to 100 using a loop.
- Write a function that computes the factorial of a number.
Reading alone is not enough — type out every example yourself and run it. Real learning comes from hands-on practice.
Discussion
1