Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

This C syntax quick reference covers the core patterns students need to read, write, and debug C programs. It helps students remember how declarations, expressions, control structures, functions, arrays, pointers, structs, and input/output fit together. A cheat sheet is useful because C is strict about punctuation, types, and memory, so small syntax errors can stop a program from compiling.

The most important ideas are declaring variables with a type, ending statements with semicolons, using braces to group code, and choosing the correct control structure. Functions organize code with a return type, name, parameter list, and body. Arrays store sequences of same-type values, pointers store memory addresses, and structs group related fields into one custom data type.

Key Facts

  • A variable declaration has the form type name; or type name = value;, such as int count = 0;.
  • Every simple C statement must end with a semicolon, such as total = total + 1;.
  • An if statement has the form if (condition) { statements } else { statements }, and the condition must be inside parentheses.
  • A for loop commonly has the form for (int i = 0; i < n; i++) { statements }, where initialization, condition, and update are separated by semicolons.
  • A function definition has the form return_type function_name(parameter_list) { statements; return value; }.
  • An array declaration has the form type name[size];, and valid indexes run from 0 to size - 1.
  • A pointer stores an address, so int *p = &x; makes p hold the address of x, and *p accesses the value stored there.
  • Formatted input and output use printf("format", values); and scanf("format", &variables);, such as scanf("%d", &age);.

Vocabulary

Declaration
A statement that tells the compiler the type and name of a variable, function, array, pointer, or struct.
Data Type
A category that determines what kind of value a variable can store and how much memory it uses.
Function
A named block of code that can receive parameters, perform a task, and optionally return a value.
Array
A fixed-size sequence of values of the same type stored in consecutive memory locations.
Pointer
A variable that stores the memory address of another value.
Struct
A user-defined type that groups related variables, called fields or members, under one name.

Common Mistakes to Avoid

  • Forgetting a semicolon after a statement is wrong because C uses semicolons to mark the end of most statements.
  • Using = instead of == in a condition is wrong because = assigns a value, while == compares two values.
  • Accessing array[index] where index equals the array size is wrong because C arrays start at 0 and end at size - 1.
  • Passing a variable to scanf without & is wrong for basic variables because scanf needs the variable’s memory address to store input.
  • Using an uninitialized variable is wrong because its value is unpredictable and may cause incorrect results.

Practice Questions

  1. 1 Write a C declaration for an integer variable named score and initialize it to 95.
  2. 2 What values of i are printed by this loop: for (int i = 0; i < 4; i++) printf("%d ", i);?
  3. 3 Given int x = 10; int *p = &x; *p = 25;, what is the value of x after these statements run?
  4. 4 Explain why C requires both a type and a name when declaring a variable.