← Back to C Course | Chapter 1: Introduction & Basics | Lesson 5 of 21

C Syntax & Structure

Semicolons

Every C statement must end with a semicolon so the compiler knows exactly where one instruction stops and the next begins; forgetting one is one of the most common beginner errors, and it often produces a confusing error on the following line instead.

Example: Semicolons

c
#include <stdio.h>
int main() {
	int x = 10;
	printf("%d", x);
	return 0;
}

Curly Braces

Curly braces { } group multiple statements into a single block, defining the body of a function, loop, or conditional. The compiler treats everything between a matching pair as one unit that executes (or doesn't) together.

Example: Curly Braces

c
#include <stdio.h>
int main() {
	{
		printf("Grouped inside braces");
	}
	return 0;
}

Tokens

A token is the smallest meaningful piece the compiler recognizes when reading your source code -- keywords, variable names, numbers, symbols like + or ;, and string literals are all individual tokens the compiler parses one at a time.

Example: Tokens

c
#include <stdio.h>
int main() {
	int total = 100;
	printf("%d", total);
	return 0;
}

Case Sensitivity

C treats uppercase and lowercase letters as entirely different characters, so main must be written exactly in lowercase, and variables named total and Total are two separate, independent variables in the same program.

Example: Case Sensitivity

c
#include <stdio.h>
int main() {
	int total = 5;
	int Total = 10;
	printf("%d %d", total, Total);
	return 0;
}

Indentation

Consistent indentation doesn't affect how the compiler runs your code -- C ignores whitespace -- but it's essential for you and other developers to visually trace which statements belong inside which block, especially in nested loops or conditionals.

Example: Indentation

c
#include <stdio.h>
int main() {
	if (1) {
		printf("Indentation shows nesting");
	}
	return 0;
}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.