Introduction
Compiling a C file
gcc -o source source.c
./source
Breakdown:
gcc: The GNU C compiler.source.cpp: Your C file.-o program: Output flag. “Name the final executablesourceinstead of the defaulta.out”
So this command:
➡️ Compiles
source.c➡️ Produces an executable file named
source
If you skip -o source:
gcc source.c
./a.out
Comparison with C++
1. Don't have OOP features
C has:
No classes
No inheritance
No polymorphism
You want OOP? Congrats, you fake it using:
structfunction pointers
2. printf instead of std::cout
printf("%d", x);
printf("%d", 3.14); // compiles fine, prints garbage
3. No references. Only pointers.
4. Memory management
No new/delete.
Just:
malloc()
free()
And if you forget free(): memory leak
5. No function overloading
// C++
int add(int, int);
float add(float, float);
// C
int add_int(int, int);
float add_float(float, float);
6. Header files are… primitive
No namespaces. No fancy modules.
7. Strings are just char arrays
char str[10] = "hello";
8. No exceptions
No try/catch. Handle potential crashes manually.
if (ptr == NULL) {
// handle error
}
Last modified: 25 March 2026