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
- Expression/Assignment:
x = y + 1;
- Selection: if/else, switch
- Iteration: for, while, do-while
- Jump:
break
,continue
,return
,goto
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
- Is
printf("hi\n")
a statement without a semicolon? - What kind of statement is
return x;
?
Show answers
- No. You need the semicolon:
printf("hi\n");
- A jump statement.