C Programming · Lesson 1 of 10 · Updated ·
Introduction to C — First Program, Compilation and Program Structure
C is one of the oldest popular languages (1972), and it's still everywhere: operating systems (Linux, Windows kernels), embedded devices, databases and the Python interpreter itself are written in C. Learning C teaches you how computers really work — memory, addresses, bytes.
1. Your first program
#include <stdio.h>
int main(void) {
printf("Hello, Skills101!\n");
return 0;
}
Hello, Skills101!
| Line | Meaning |
|---|---|
#include <stdio.h> | include the standard input/output library (for printf) |
int main(void) | execution starts here; returns an int |
printf("…\n") | print text; \n is a new line |
return 0; | tell the operating system "finished successfully" |
Every statement ends with ;. Blocks are inside { }. C is case-sensitive (Main ≠ main).
2. How a C program is compiled
- Preprocessor — handles lines starting with
#: pastes in header files, replaces macros. - Compiler — turns C into assembly and checks syntax and types.
- Assembler — turns assembly into machine code (object file
.o). - Linker — joins your object files with libraries (like the code for
printf) into an executable.
With GCC: gcc hello.c -o hello then ./hello (Linux/Mac) or hello.exe (Windows). Beginners on Windows can install MinGW or use an online compiler — or our coding practice.
3. Printing numbers
#include <stdio.h>
int main(void) {
int marks = 92;
float cgpa = 8.75f;
printf("Marks: %d\n", marks);
printf("CGPA: %.2f\n", cgpa);
printf("Sum: %d\n", 10 + 5);
return 0;
}
Marks: 92
CGPA: 8.75
Sum: 15
%d, %f are format specifiers — placeholders replaced by the values after the comma. More in the next lesson.
4. Comments
// single-line comment (C99 and later)
/* multi-line
comment */
5. Structure of a C program
/* documentation: what this program does */
#include <stdio.h> ← header files
#define PI 3.14159 ← macros / constants
int count = 0; ← global variables
int square(int n); ← function declarations (prototypes)
int main(void) { ← main function
...
return 0;
}
int square(int n) { ← other function definitions
return n * n;
}
6. Why C is "middle level"
C has high-level features (functions, loops, structures) but also low-level access (pointers, memory addresses, bits). It is fast because it compiles to machine code and does very little checking at runtime — which also means you must be careful (no automatic bounds checks).
Common mistakes
- Forgetting
#include <stdio.h>→ warnings or errors forprintf. - Missing semicolons or the
\nat the end of output. - Writing
void main()— the standard isint main(void)returning 0.
Quick recap
- C is fast, close to hardware, and used in OS and embedded systems.
- Preprocessor → compiler → assembler → linker.
mainis the entry point;printfwith format specifiers prints values.- Statements end with
;; C is case-sensitive.