← Back to C Course | Chapter 1: Introduction & Basics | Lesson 6 of 21

C Statements

A statement is the smallest complete instruction C executes, and a C program is fundamentally a sequence of declaration, expression, and compound statements executed in order.

What is a Statement?

A statement is the smallest complete instruction in C that the compiler can execute, such as declaring a variable, calling a function, or evaluating an expression, and a C program is fundamentally a sequence of statements executed in order.

Example: What is a Statement?

c
#include <stdio.h>
int main() {
	int x = 5;
	printf("%d", x);
	return 0;
}

Expression Statements

An expression statement consists of an expression, like an assignment or a function call, followed by a semicolon, and it's the most common kind of statement, executed purely for its side effect.

Example: Expression Statements

c
#include <stdio.h>
int main() {
	int x;
	x = 5 + 3;
	printf("%d", x);
	return 0;
}

Compound Statements (Blocks)

A compound statement, or block, groups multiple statements together inside curly braces, letting several statements be treated as a single unit wherever the language expects just one statement, such as inside an if or loop.

Example: Compound Statements (Blocks)

c
#include <stdio.h>
int main() {
	int x = 5;
	if (x > 0) {
		printf("Positive");
		printf(", counted as one block");
	}
	return 0;
}

Declaration Statements

A declaration statement introduces a new variable (or function), specifying its type and name, and optionally an initial value, making that identifier available for use in the statements that follow.

Example: Declaration Statements

c
#include <stdio.h>
int main() {
	int age = 25;
	printf("%d", age);
	return 0;
}

Statement Termination with Semicolons

Every simple statement in C, apart from compound statements enclosed in braces, must be terminated with a semicolon, which tells the compiler exactly where one instruction ends and the next one begins.

Example: Statement Termination with Semicolons

c
#include <stdio.h>
int main() {
	int a = 1;
	int b = 2;
	printf("%d", a + b);
	return 0;
}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.