Back to course

Comments, Tokens, and Basic Syntax Rules

C Language: 0 to Hero - The Complete Beginner's Guide

Lesson 5: Comments, Tokens, and Basic Syntax Rules

Comments

Comments are non-executable text used to explain the code. They are ignored by the compiler.

1. Single-Line Comments (C99 and later)

c // This is a single-line comment int x = 10; // Inline explanation

2. Multi-Line Comments (C89/ANSI C)

c /* This is a multi-line comment. It can span several lines and is useful for block documentation. */

C Tokens

A token is the smallest individual unit in a C program. Tokens are categorized as:

  1. Keywords: Reserved words that have predefined meanings (e.g., int, if, while).
  2. Identifiers: Names given to variables, functions, arrays, etc. (Must start with a letter or underscore, cannot be a keyword).
  3. Constants: Fixed values that do not change during execution (e.g., 10, 3.14, 'A')
  4. Strings: Sequences of characters enclosed in double quotes (e.g., "Hello").
  5. Operators: Symbols used for operations (e.g., +, =, *).
  6. Separators/Punctuators: Symbols used to group or separate things (e.g., {, }, ;, ().

Syntax Rules

  1. Case Sensitivity: C is case-sensitive. MyVariable is different from myvariable.
  2. Statement Termination: Every statement (instruction) must end with a semicolon (;).
  3. Whitespace: Whitespace (spaces, tabs, newlines) is generally ignored by the compiler, allowing for flexible code formatting, except within string literals or tokens.