C Statements

3 min read ·

Statements in C are instructions that the program executes. Every line of code that performs an action is considered a statement.
Each statement must end with a semicolon, which tells the compiler that the instruction is complete.

Explanation

printf() prints output to the screen
return 0 ends the program
Note

Missing a semicolon at the end of a statement will cause a compilation error.

Types of C Statements

C statements can be broadly divided into four main types
Declaration statements Assignment statements Control statements Function call statements

1. Declaration Statements

These statements are used to declare variables before using them.

Explanation

int a declares an integer variable
float b declares a floating point variable
Pro Tip

Always initialize variables before using them to avoid unexpected behavior.

2. Assignment Statements

Assignment statements are used to assign values to variables.

Explanation

x = 20 assigns value 20 to variable x
Note

You can also assign values during declaration like int x = 20;

3. Control Statements

Control statements are used to control the flow of execution in a program.

if Statement Example

if else Example

loop Example using for

Explanation

if checks a condition
else runs when condition is false
for loop repeats code multiple times
Real World Scenario

Control statements are used in real applications like checking login credentials or repeating tasks such as processing multiple records.

4. Function Call Statements

These statements call functions to perform specific tasks.

Explanation

greet() is a function call
The function executes when it is called
Caution

A function must be declared before it is called, otherwise the compiler will throw an error.

Combining Multiple Statements

Explanation

Multiple statements work together to perform a complete task
This is how real programs are structured
Goal Achieved

You now understand different types of C statements and how they are used in real programs.

Exercise

Write a C program that takes a number as input and checks whether it is even or odd using an if else statement.