C Syntax
C syntax defines the rules for writing valid programs: how statements are structured, how blocks are grouped with curly braces, and how whitespace is treated. Statements always end with a semicolon, and blocks of code are enclosed in { } braces.
C is case-sensitive, so `Total` and `total` are different identifiers. Indentation is not required by the compiler but is essential for readable code.
int main() {
statement1;
statement2;
}Statements and blocks
Each instruction (a statement) ends with a semicolon. Related statements are grouped into a block using curly braces, such as the body of a function or an if statement.
Identifiers and case sensitivity
Names for variables and functions can contain letters, digits and underscores but cannot start with a digit. C distinguishes uppercase from lowercase letters in all identifiers.
#include <stdio.h>
int main() {
int age = 25;
printf("Age: %d\n", age);
return 0;
}Age: 25A block is enclosed in braces, and each statement ends with a semicolon.
#include <stdio.h>
int main() {
int Age = 1;
int age = 2;
printf("%d %d\n", Age, age);
return 0;
}1 2Age and age are treated as two different variables because C is case-sensitive.
Key points
- Statements end with a semicolon.
- Curly braces { } group statements into blocks.
- C is case-sensitive.
- Indentation improves readability but is not required by the compiler.
