In the C language, executable instructions fall into five primary categories: empty statements, expression statements, function call statements, compound statements, and control statements.
Empty Statements
An empty statement consists solely of a terminating semicolon. It performs no operation but occupies a syntactic position where a statement is required.
#include <stdio.h>
int main() {
; // Placeholder with no effect
return 0;
}
This construct is typically inserted when a syntactical requirement for a statement exists, yet no specific action needs to be performed at that moment.
Expression Statements
Program structures rely heavily on expressions. These consist of operators and operands (variables, constants, or returned values), each yielding a definite result. When an expression concludes with a semicolon, it becomes an expression statement.
#include <stdio.h>
int main() {
int counter = 10; // Variable assignment
int limit = 5; // Initialization
int difference = counter - limit; // Arithmetic evaluation
return 0;
}
Developers utilize these primarily for variable updates, conditional checks, or mathematical operations.
Function Call Statements
A functon represents a cohesive set of instructions designed to accomplish a specific task. The entry point, usually named main, serves as the primary example. Invoking any routine generates a function call statement.
#include <stdio.h>
int calculate_sum(int val_one, int val_two) {
return val_one + val_two;
}
int main() {
puts("Execution Started"); // Standard library invocation
int outcome = calculate_sum(3, 7); // Custom logic call
return 0;
}
Both standard library functions like puts and user-defined routines constitute function calls within the program flow.
Compound Statements
Referred to as blocks, compound statements group zero or more individual instructions within curly braces {}. They allow multiple lines of code to function as a single unit.
#include <stdio.h>
int main() {
int idx = 0;
int values[] = {10, 20, 30};
for(idx = 0; idx < 3; idx++) {
printf("%d ", values[idx]); // Block body execution
} // Block termination
return 0;
}
Characteristics include:
- Defined using
{}to encapsulate multiple statements. - Eligible for nesting within structures like conditionals or loops.
- Variables declared inside possess local scope, restricting visibility to the block itself.
Control Statements
Control statements dictate the sequence of execution and structural organization. There are nine distinct forms categorized into three logical groups:
- Selection/Branching:
ifandswitchdetermine which path to take based on conditions. - Iteration/Loops:
for,while, anddo-whilerepeat execution until a condition changes. - Jumping/Transfer:
break,continue,goto, andreturnalter the flow without following the normal sequential order.