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:
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:
C Tokens: Please have a look at the following image for the complete list of C tokens.
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:
- Always starts with a letter.
- Underscore ( _ ) is treated as a letter.
- It cannot contain blank spaces in between.
- It cannot be a Key Word.
- 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.
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.