C syntax is the set of rules for writing valid code. Programs are built from tokens (keywords, identifiers, literals, operators). Statements end with ;, blocks use { }, and C is case-sensitive: Count and count are different names.
Remember
int count = 10; /* declaration + initialization */
count = count + 1; /* expression statement */
{ /* block: group of statements */
int local = 5;
}
/* whitespace and newlines are mostly ignored */
Reference
Cheat Sheet
Keep these facts handy while you work with Syntax in C.
Topic
Detail
Statement
Ends with a semicolon ;
Block
Statements grouped in { }
Case
Main is not main
Literals
42, 3.14, 'A', "text"
Code
C Examples
Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Comments.
Example 1 — Case sensitivity and blocks
Two different variables and an inner block with its own scope.
C
#include <stdio.h>
int main(void) {
int total = 10;
int Total = 20;
{
int total = 99; /* shadows outer total */
printf("inner total: %d\n", total);
}
printf("total: %d, Total: %d\n", total, Total);
return 0;
}
Output
inner total: 99
total: 10, Total: 20
How It Works
total and Total are separate identifiers.
The inner block declares its own total, hiding the outer one.
After the block ends, the outer total is visible again.
Edge Cases & Pitfalls
Check these before relying on Syntax in real programs.
semi
Missing semicolon
The compiler often reports the error on the next line. Check the line above the reported one.
braces
Unbalanced braces
Every { needs a matching }. Use consistent indentation so mismatches are easy to see.
Remember
Key Takeaways
Terminate: statements end with ;.
Case: identifiers are case-sensitive.
Blocks:{ } create scope.
One line: C syntax is the set of rules for writing valid code.
Frequently Asked Questions
Mostly no. Whitespace separates tokens, but extra spaces and newlines are ignored. It matters inside string literals and preprocessor lines.
The parser notices a problem only when the next token does not fit. A missing semicolon is therefore often reported on the following line.
Continue with "C Comments" next. Add notes to your code with // and /* */ comments. The C Fundamentals hub lists every topic in order.