C - Statements

Statements in C

A statement is a single instruction for the compiler to execute. Most C statements end with a semicolon (;). A program is a sequence of statements executed in order unless control flow changes it.

Learning Objectives

  • Identify common statement forms in C.
  • Write simple assignment and expression statements.
  • Recognize selection and iteration statements as control flow.

Prerequisites

Example

int number1 = 1;                 // declaration + initialization (assignment)
int number2 = 2;                 // declaration + initialization
int number3 = number1 + number2; // expression statement

Here, three statements execute in order and compute a result.

Types of Statements

Common Pitfalls

  • Forgetting the semicolon ; at the end of a statement.
  • Declaring variables after statements in older C standards; keep declarations at the top of a block if targeting C89.

Checks for Understanding

  1. Is printf("hi\n") a statement without a semicolon?
  2. What kind of statement is return x;?
Show answers
  1. No. You need the semicolon: printf("hi\n");
  2. A jump statement.