C Programming

Lesson 1 of 11

C Basics

C is a compiled, statically-typed language from 1972 that still powers operating systems, databases, and language runtimes today. Learning C means learning how a computer actually works, no hidden garbage collector, no implicit conversions you didn't ask for, just you and the machine.

Your first program

C
  • #include <stdio.h> pulls in the standard I/O library, so printf exists.
  • int main(void) is the entry point every C program starts from, it returns an int exit code to the operating system, 0 means "success".
  • printf formats and prints text, \n is a newline escape sequence, unlike Python there's no automatic newline after a print.

Compiling and running

C is compiled ahead of time, there's no interpreter:

gcc hello.c -o hello
./hello

gcc translates your .c source file into a native executable, -o hello names the output file. Every time you change the source, you recompile before running again.

Variables and types

Unlike Python or JavaScript, every variable in C has a fixed, explicit type:

C

There's no var/let inference, you declare the type up front and it never changes. This is why C is fast, the compiler knows exactly how much memory each variable needs and never has to check types at runtime.

TIP

C has no built-in string type, a "string" is really just an array of char ending in a special \0 (null terminator) byte. You'll see why that matters a lot once we get to pointers.

📝 C Basics Quiz

Passing score: 70%
  1. 1.What does main() returning 0 signal to the operating system?

  2. 2.In C, a variable's type must be declared up front and cannot change later.

  3. 3.The command to compile hello.c into an executable called hello with gcc is: gcc hello.c -o ____