Basic Syntax of C Program

Basic Syntax of C Program

In this article, I am going to discuss the Basic Syntax of the C Program in detail. Please read our previous article, where we discussed how to create a project using CodeBlocks IDE as well as how to compile debug and run projects in CodeBlocks IDE. At the end of this article, you will understand the Syntax of the C Language.

Whitespace in C Program

Whitespace is the term used in C to describe blanks, tabs, newline characters, and comments. Whitespace separates one part of a statement from another and helps the compiler to identify where one element in a statement, such as an int, ends and the next element begins.

Example: int age;

There must be at least one whitespace character (usually space) between int and age for the compiler to be able to distinguish them.

Semicolon in C Program

The semicolon (;) is used to mark the end of a statement and the beginning of another statement. The absence of a semicolon at the end of any statement will mislead the compiler to think that this statement is not yet finished and it will add the next consecutive statement after it, which may lead to a compilation (syntax) error. For example:

Semicolon in C Program

In the above program, we have omitted the semicolon from the printf(“…”) statement, hence the compiler will think that starting from printf until the semicolon after return 0 statement, is a single statement and this will lead to a compilation error.

Tokens in C Langauge

A Token is a small unit of a program. Token consists of identifiers, keywords, constants, data types, operators & special symbols. C tokens are basically the building blocks of a C program. The C program can also be called a collection of various tokens. For example:

Tokens in C Langauge

C Tokens: Please have a look at the following image for the complete list of C tokens.

Basic Syntax of C Program
Identifiers in C Programming Language:

Identifiers are the name given to various elements such as variables, functions, etc. They are a sequence of letters and digits. The rules of Identifiers are:

  1. Always starts with a letter.
  2. Underscore ( _ ) is treated as a letter.
  3. It cannot contain blank spaces in between.
  4. It cannot be a Key Word.
  5. It should be less than 32 characters, which increases the portability in ANSI C.
Keywords in C Program

Keywords are pre-defined meaning words. These words are specifically defined with a meaning which cannot be changed. All Keywords are usually in lowercase such as void, int, do, if, else, return, break, switch, etc. ANSI C originally had 32 keywords, while a few more have been added later.

Keywords in C Program
Follow Us On