Example 1 — Hello, World!
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
} 
This page is a self-contained introduction to C programming—no prior coding experience required. You will understand what C is, write your first program, and learn how source code becomes a running application.
History & role.
#include & main.
First program.
gcc workflow.
Career value.
Core concepts.
C is a general-purpose, procedural programming language that is compact, fast, and close to the machine. It powers operating systems (Linux, parts of Windows), embedded firmware, databases, game engines, and the runtimes behind languages like Python and PHP.
C is widely used because it gives programmers direct control over memory and hardware while staying portable across platforms. Many modern languages borrowed C’s syntax and ideas—learning C makes every other language easier to pick up.
It is crucial to understand how computer memory works when programming in C (and in most other languages too). Variables live in memory, functions use the stack, and careful management prevents bugs and security issues.
Start with printf, variables, and simple logic. Master the basics on this page before moving to advanced topics like pointers and dynamic memory.
In the early 1970s, Dennis Ritchie at Bell Labs created C to rewrite the Unix operating system in a portable, efficient language. Ken Thompson had built B; C improved on B and BCPL with types, structures, and direct memory access.
Officially, Dennis Ritchie is known as the founder of the C language. It was designed to fix limitations in earlier languages such as B and BCPL.
| Language | Year | Developed By |
|---|---|---|
| Algol | 1960 | International Group |
| BCPL | 1967 | Martin Richards |
| B | 1970 | Ken Thompson |
| C (Traditional) | 1972 | Dennis Ritchie |
| K&R C | 1978 | Kernighan & Ritchie |
| ANSI C | 1989 | ANSI Committee |
| ANSI/ISO C | 1990 | ISO Committee |
| C99 | 1999 | Standardization Committee |
| C11 | 2011 | ISO/IEC |
| C17 | 2018 | ISO/IEC |
Every C program follows the same skeleton: include headers, define main, run statements, return an exit code.
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
} #include <stdio.h> pulls in declarations for printf and related I/O.main when your executable starts.; — missing semicolons are among the most common beginner errors.{ } — group multiple statements; always brace if and loop bodies in real code.// line comment (C99+) or /* block */.C is a compiled language: you write human-readable source code (.c), a compiler turns it into machine code, and a linker produces an executable file.
gcc hello.c -std=c11 -Wall -o hello
./hello /* Linux / macOS */
hello.exe /* Windows */ -std=c11 — use the C11 language standard (widely supported).-Wall — enable common warnings (highly recommended while learning).-lm — link the math library when using math.h on GCC/Clang.As you continue learning C, these are the main ideas you will encounter. You do not need to master them all today—this overview helps you see the big picture.
| Concept | What it does |
|---|---|
| Variables & types | Store data (int, float, char, etc.) |
| Operators | Arithmetic, comparison, and logical operations |
| Control flow | if, else, switch for decisions |
| Loops | for, while, do-while for repetition |
| Functions | Reusable blocks of code with parameters and return values |
| Arrays & strings | Collections of values; strings are char arrays |
| Pointers | Variables that hold memory addresses |
| Structs | Group related fields into one custom type |
| Concept | Example |
|---|---|
| Output | printf("Age: %d\n", age); |
| Input | scanf("%d", &age); |
| Integer variable | int count = 0; |
| Condition | if (x > 0) { ... } |
| Counted loop | for (int i = 0; i < n; i++) { ... } |
| Include header | #include <string.h> |
Five starter programs you can type, compile, and run today. Save each as a .c file and use gcc as shown above.
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
} #include <stdio.h>
int main(void) {
int age = 20;
float gpa = 3.85f;
char grade = 'A';
printf("Age: %d\n", age);
printf("GPA: %.2f\n", gpa);
printf("Grade: %c\n", grade);
return 0;
} #include <stdio.h>
int main(void) {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered: %d\n", num);
return 0;
} scanf needs the address of the variable (&num) so it can write into memory.
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main(void) {
printf("Sum = %d\n", add(3, 5));
return 0;
} #include <stdio.h>
int main(void) {
int n;
printf("Enter n: ");
scanf("%d", &n);
if (n % 2 == 0)
printf("%d is even\n", n);
else
printf("%d is odd\n", n);
return 0;
} This shows basic decision-making: one branch runs when the condition is true, the other when it is false.
| Language | Style | Best for beginners when… |
|---|---|---|
| C | Procedural, compiled | You want deep fundamentals and systems understanding |
| Python | High-level, interpreted | You want quick results with less syntax overhead |
| C++ | Multi-paradigm, compiled | You know C basics and need OOP + templates |
| Java | OOP, JVM bytecode | You target enterprise apps and Android |
You create a text file with C code: headers, functions, and main.
gcc expands #include, checks syntax, and produces object code.
The linker combines your object file with the C library into an executable.
main starts; printf output appears in your terminal.
main, and typically return 0;.gcc file.c -std=c11 -Wall -o out; many compilers are available.-Wall and fix warnings immediatelystudentCount, not x)if and loop body, even one-linersgets() (removed from C11; unsafe)== (use strcmp when you learn strings)return 0; in main without reasonIf you know C programming, you can quickly pick up other languages that use the same core ideas—curly braces, functions, and typed variables. The classic The C Programming Language (1978) by Kernighan and Ritchie popularized “Hello, world” as the first program every beginner writes.
Copy any example from this page into the online compiler and run it instantly.
12 people found this page helpful