C Statements

In C programming, statements are individual instructions or actions that make up a program. Statements are executed sequentially, and they control the flow of the program.

Declaration Statements

Declaration statements are used to declare variables or functions. They tell the compiler about the data type and name of variables or the return type and name of functions.

int age; // Variable declaration statement double calculateSalary(); // Function declaration statement

Assignment Statements

Assignment statements are used to assign values to variables. They use the assignment operator (=) to store a value in a variable.

int x; // Declaration statement x = 10; // Assignment statement

Expression Statements

Expression statements are used to evaluate expressions. They often include expressions followed by a semicolon, and the result of the expression is typically discarded.

int result; // Declaration statement result = 2 + 3; // Expression statement (result is 5, but not used here)

Conditional Statements (Selection Statements)

Conditional statements allow you to make decisions based on conditions. The most common conditional statements are if, else if, and else.

int age = 25; if (age >= 18) { printf("You are an adult.\n"); } else { printf("You are a minor.\n"); }

Loop Statements (Iteration Statements)

Loop statements allow you to repeat a block of code multiple times. Common loop statements include for, while, and do-while.

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

Jump Statements

Jump statements are used to transfer control to another part of the program. Common jump statements are break, continue, and return.

int add(int a, int b) { return a + b; // Return statement }

Compound Statements (Block Statements)

Compound statements are used to group multiple statements together. They are enclosed in curly braces {} and create a local scope.

int x = 10; { int y = 5; printf("x + y = %d\n", x + y); }

Control Statements

Control statements control the flow of a program, often in combination with conditional or loop statements. They include switch and goto statements (though goto should be used sparingly).

int choice = 2; switch (choice) { case 1: printf("Option 1 selected.\n"); break; case 2: printf("Option 2 selected.\n"); break; default: printf("Invalid option.\n"); }

Conclusion

Statements are individual instructions that constitute a program. They encompass declaration statements for variables and functions, assignment statements for assigning values to variables, expression statements for evaluating expressions, control statements for making decisions and creating loops, jump statements for altering the flow of the program, and compound statements for grouping multiple statements within a local scope. Understanding and effectively using these statements is essential for writing functional and organized C code.