Basic Syntax of C Program

Basic Syntax of C Program

In this article, I am going to discuss the Basic Syntax of 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 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 beginning of another statement. Absence of 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 compilation (syntax) error. For example:

Semicolon - Syntax of C Language

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. A C program can also be called as a collection of various tokens. For example:

Tokens in C Program

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

C Tokens - Syntax of C Language

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 - Syntax of C Language

In the next article, I am going to create a sample C program and then try to explain the different parts of a C program in detail. Here, in this article, I try to explain the Basic Syntax of C Programming Language and I hope you enjoy this Syntax of C Language article.

Leave a Reply

Your email address will not be published. Required fields are marked *