📘 C Programming Core Concepts
🔧 From “Hello, world!” to clean termination — master the building blocks
📦 Include Statements
These are like saying, "Hey, computer, I'm going to use some special tools, so get ready." It's the beginning of your program.
#include <stdio.h>
➕ more insight:
stdio.h = standard input/output library. Without it, printf and scanf won't work. You can also include other headers like <math.h> for advanced math.
🚀 Main Function
This is like the starting point of your program. It's where the computer begins reading and doing what you tell it.
int main()
{
// Your code goes here
return 0; // This means everything went well
}
💡 deeper dive:
int main() is mandatory for executable C programs. Returning 0 signals success to the OS; non-zero indicates an error. Curly braces {} define the function body.
💬 Comments
Comments are like sticky notes to yourself (or others) to explain what your code is doing. The computer ignores them.
// This is a comment. It helps explain things. /* Multi-line comment can span several lines */
✍️ best practice: Use comments to explain "why", not "what". Keep them updated. Modern IDEs highlight comments for clarity.
📋 Declarations
Here, you tell the computer about the boxes (variables) you want to use. It's like saying, "I'm going to store some information, get ready."
int age; // box for whole numbers (integer) float height; // box for decimal numbers (float)
🧠 advanced detail: C is statically typed — you must declare variable type before use. Other types:
char, double. Initialization recommended: int age = 0;
🎤 Input / Output
You might want your program to talk to the user or listen to what they say.
printf() is like talking, and scanf() is like listening.
printf("Enter your age: ");
scanf("%d", &age);
🔍 format specifiers:
%d for integers, %f for floats, %c for char. &age passes the memory address so scanf can store the value.
⚙️ Actions
This is where the real work happens. You tell the computer what to do with the information it has.
height = 5.8; // Assigning a value to the height box age = age + 1; // increment age
✨ operators in action: assignment
=, arithmetic (+ - * / %), comparison, logical ops. Actions transform data.
🖨️ Output
You might want the computer to show you something.
printf() is again your friend. This line tells the computer to say the age and height it knows.
printf("Age: %d, Height: %.1f\n", age, height);
📢 advanced formatting:
%.1f rounds to 1 decimal. \n adds newline. You can combine text, variables and escape sequences.
🏁 The End
The
return 0; at the end is like saying, "I'm done, and everything went okay." It's a way to wrap up your program.
return 0; // success status to operating system
✅ program exit status:
return 0 from main indicates normal termination. Any other number signals error. Some compilers allow void main() but standard C requires int main().
🧪 Two Complete Examples – See C in Action
🔢 Example 1: Age Checker
This program asks for your age, then tells you if you're an adult (18 or older) or a minor. It uses
printf, scanf, and an if-else action.
#include <stdio.h>
int main() {
int age;
printf("How old are you? ");
scanf("%d", &age);
if (age >= 18) {
printf("You are an adult! 🎉\n");
} else {
printf("You are a minor. 🌱\n");
}
return 0;
}
💻 Sample output (if user types 20):
How old are you? 20
You are an adult! 🎉
How old are you? 20
You are an adult! 🎉
📖 Easy explanation:
if (age >= 18) checks if the number you entered is 18 or bigger. If yes, it prints the adult message; otherwise, it prints the minor message. Super simple decision-making!
📐 Example 2: Rectangle Area
This program calculates the area of a rectangle. You enter length and width, then the computer multiplies them and shows the result.
#include <stdio.h>
int main() {
float length, width, area;
printf("Enter length of rectangle: ");
scanf("%f", &length);
printf("Enter width of rectangle: ");
scanf("%f", &width);
area = length * width; // action: multiplication
printf("The area is: %.2f square units.\n", area);
return 0;
}
💻 Sample output (length=5, width=3):
Enter length of rectangle: 5
Enter width of rectangle: 3
The area is: 15.00 square units.
Enter length of rectangle: 5
Enter width of rectangle: 3
The area is: 15.00 square units.
📖 Easy explanation:
area = length * width does the math. %.2f prints the result with two decimal places (like 15.00). This shows how variables, input, and output work together to solve a real problem.


If you have any doubts, Please let me know