C Syntax

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Syntax?

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 */

Cheat Sheet

Keep these facts handy while you work with Syntax in C.

TopicDetail
StatementEnds with a semicolon ;
BlockStatements grouped in { }
CaseMain is not main
Literals42, 3.14, 'A', "text"

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;
}

How It Works

  1. total and Total are separate identifiers.
  2. The inner block declares its own total, hiding the outer one.
  3. 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.

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.

Next: Comments

Add notes to your code with // and /* */ comments.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful