Master C programming fundamentals including syntax, data types, variables, arithmetic operators, and control flow with runnable code examples.
Introduction to C Programming
Created by Dennis Ritchie at Bell Labs in 1972, C is an efficient, procedural, statically typed programming language that powers operating system kernels (Linux, macOS, Windows), embedded devices, real-time engines, and database systems worldwide.
Understanding C gives you direct insight into how computers manage memory, CPU registers, and hardware resources.
Anatomy of a C Program
Every standard C program starts execution from the main() function:
c (ISO Standard)#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
Breakdown of the Code:
#include <stdio.h>: Preprocessor directive that imports standard input/output functions, such asprintf().int main(): The entry point function required in every executable C application.printf(...): Formats and outputs characters to the standard console.return 0;: Returns exit status code0to the operating system, signaling successful termination.
Fundamental Data Types in C
| Data Type | Keyword | Typical Size | Value Range / Specifier |
|---|---|---|---|
| Integer | int | 4 bytes | -2,147,483,648 to 2,147,483,647 (%d) |
| Character | char | 1 byte | Single ASCII character (%c) |
| Single Precision Float | float | 4 bytes | 6–7 decimal digits (%f) |
| Double Precision Float | double | 8 bytes | 15–17 decimal digits (%lf) |
c (ISO Standard)#include <stdio.h> int main() { int age = 21; char initial = 'M'; float temperature = 98.6f; double preciseValue = 3.141592653589793; printf("Age: %d\n", age); printf("Initial: %c\n", initial); printf("Temperature: %.1f\n", temperature); printf("Pi: %.6lf\n", preciseValue); return 0; }
Control Flow: Conditionals and Loops
1. Conditional Logic (if-else)
c (ISO Standard)#include <stdio.h> int main() { int number = 17; if (number % 2 == 0) { printf("%d is even.\n", number); } else { printf("%d is odd.\n", number); } return 0; }
2. For Loops & While Loops
c (ISO Standard)#include <stdio.h> int main() { printf("Counting 1 to 5 with a for loop:\n"); for (int i = 1; i <= 5; i++) { printf("%d ", i); } printf("\n"); return 0; }
Next Steps in Your C Journey
- Modularize your code using Functions in C Programming.
- Store sequential collections with Arrays in C Programming.
- Master hardware memory directly in the Pointers in C Guide.
- Practice coding with our Fibonacci Series Program or Prime Number Program.