Skip to content
CurriculumChapter 01 · Foundations
BeginnerHigh focus~12 min

C Language Basics

C is small enough to learn completely and close enough to the machine that every line has a cost. Start with the shape of a source file.

In plain English

A C program is a recipe. The ingredients are variables, the steps are statements, and main is the first step.

01

A program is a collection of functions

Execution begins at main(). Braces group statements into a block, a semicolon ends an expression statement, and declarations tell the compiler what a name means before it is used. Preprocessor lines begin with # and are handled before compilation. Everything else is either a declaration, a definition, or a statement.

chapter-01.cC
#include <stdio.h>

int main(void) {
    int answer = 42;
    printf("answer = %d\n", answer);
    return 0;
}
02

Character set, identifiers, and keywords

C source is written using a small character set: letters, digits, punctuation, and whitespace. Identifiers name variables, functions, and types. They must begin with a letter or underscore and may contain letters, digits, and underscores. Keywords such as int, if, return, and struct are reserved and cannot be reused as identifiers. Comments are removed before the compiler sees the code.

chapter-01.cC
/* valid identifiers */
int score;
int _internal;
int player2_score;

/* invalid: starts with a digit, or uses a keyword */
/* int 2player; */
/* int return; */

Key takeaways

  • C programs are built from functions and start at main().
  • Statements end with semicolons; blocks use braces.
  • Identifiers follow naming rules and cannot be keywords.
  • Comments are for humans and are removed before compilation.

Common pitfalls

  • Forgetting a semicolon or closing brace.
  • Using a keyword as a variable name.
  • Assuming whitespace changes meaning; C is free-form.

Key focus

  • Expect questions on valid identifiers and keywords.
  • Know that main is the entry point, not necessarily the first function in the file.

Quick check

0 / 2 answered

1. Which of these is a valid C identifier?

2. Where does execution begin in a standard C program?