C C++

C Statements


Introduction

A statement is an instruction that tells the computer to perform a specific action. Every C program is made up of one or more statements that are executed in sequence unless the program flow is changed by control statements such as if, switch, for, or while.

Statements are one of the fundamental building blocks of C programs. Understanding the different types of statements will help you write clear, organized, and efficient code.

What Is a Statement?

A statement is a complete instruction that the compiler can execute. Most statements in C end with a semicolon (;).

Syntax

statement;
    

Each statement performs a specific task, such as declaring a variable, assigning a value, calling a function, or controlling the flow of execution.

Expression Statements

An expression statement consists of an expression followed by a semicolon. It is the most common type of statement in C.

Example

int age = 20;

age = age + 1;

printf("%d\n", age);

count++;

Each line above is an expression statement because it performs an operation and ends with a semicolon.

Declaration Statements

A declaration statement introduces a variable and optionally initializes it.

Example

int number;

double price = 19.99;

char grade = 'A';

Declaration statements allocate storage for variables and define their data types.

Compound Statements

A compound statement, also called a block, is a group of statements enclosed in curly braces ({}). The entire block is treated as a single statement.

Syntax

{
    statement1;
    statement2;
    statement3;
}

Compound statements are commonly used in functions, loops, and conditional statements.

Selection Statements

Selection statements allow a program to choose between different execution paths based on a condition.

C provides the following selection statements:

  • if
  • if...else
  • switch

Example

if (score >= 60)
{
    printf("Passed\n");
}
else
{
    printf("Failed\n");
}

The program executes different statements depending on whether the condition is true or false.

Iteration Statements

Iteration statements repeatedly execute a block of code while a condition is satisfied.

C provides three looping statements:

  • for
  • while
  • do...while

Example

for (int i = 1; i <= 5; i++)
{
    printf("%d\n", i);
}

The loop repeatedly executes the statement block until the loop condition becomes false.

Jump Statements

Jump statements immediately transfer control to another part of the program.

C provides the following jump statements:

  • break
  • continue
  • goto
  • return

Example

for (int i = 0; i < 10; i++)
{
    if (i == 5)
    {
        break;
    }

    printf("%d\n", i);
}

In this example, the break statement immediately terminates the loop when i becomes 5.

The Null Statement

A null statement is an empty statement consisting of only a semicolon.

Syntax

;

Although it performs no action, a null statement is sometimes useful in loops or as a placeholder.

Example

while (*text++)
    ;
Note: A null statement is valid C syntax, but it should be used carefully because it can make code harder to understand.

Statement Execution Order

By default, statements are executed sequentially from top to bottom.

Example

printf("First\n");

printf("Second\n");

printf("Third\n");

The output is:

Output

First
Second
Third

Control statements can change this normal execution order.

Complete Example

The following program demonstrates several different types of statements working together.

Example

#include <stdio.h>

int main(void)
{
    int number = 5;

    if (number > 0)
    {
        for (int i = 1; i <= number; i++)
        {
            printf("%d\n", i);
        }
    }

    return 0;
}

This program contains:

  • A declaration statement.
  • An expression statement.
  • An if selection statement.
  • A for iteration statement.
  • A compound statement.
  • A return jump statement.

Common Beginner Mistakes

  • Forgetting the semicolon at the end of a statement.
  • Placing an unnecessary semicolon after an if, for, or while condition.
  • Confusing expressions with statements.
  • Missing curly braces when multiple statements belong to a control structure.
  • Using break or continue outside a loop or switch statement.
Warning: An accidental semicolon immediately after an if, for, or while statement changes the program's behavior and is a common source of bugs.

Summary

Statements are the executable instructions that make up every C program. Different types of statements perform different tasks, from declaring variables to controlling program flow.

The major categories of C statements include:

  • Expression statements
  • Declaration statements
  • Compound statements (blocks)
  • Selection statements
  • Iteration statements
  • Jump statements
  • Null statements

Mastering statements is essential because every C program is ultimately built by combining these basic language constructs.