C Programming Basic Syntax


Syntax are used in C program to write statement. It defines the rules for sequence of characters to be written in C language. It defines how should a statement start, how should a statement end, where to use operator, where to write operand, where to use brackets etc. Every C programming basic syntax may also termed as token.

C Programming Basic Syntax

Tokens in  C Programming

A C Programming is a collection of various tokens. Every smallest individual elements of C program is called as tokens. Token is either a keyword, an identifier, a constant, a variable, a string literal or any symbol that have a valid meaning in C language.

printf(“Hello, World!”);

Let us look at the above example. It includes of 5 tokens. Below is the breakdown of tokens of the above example.

printf
(
“Hello, World!”
)
;

 

Semicolons in C Programming

In C program each and every statement is end with a semicolon or  which indicates the end of one logical entity. When the compiler hit a semicolon, it understands that this is the end of current statement and beginning of the next statement. If a semicolon is absent at the end of any statement, it leads to syntax error in the program during compile time. Below are some example of various statement-

printf(“Hello, World!”);
no = no1 + no2;
return 0;

 

Comments in C Programming

Comments are the simple text in C programming which is ignored by the compiler during compilation of the program. Though it is not compulsory to write comment, but it is recommended to write comment line within your program for better understanding of it in future. It helps to improve the readability as well as understanding of the program code. In C programming, there are two ways to write comments.

  • Single line comment: With single line comment we can write a single comment line. For this we can use  // 
  • Multiple line comment: If you want to write multiple comment line, then you can do this by writing your comments line with is  /*  and  */ .   /*  indicates the starting of comment line and  */  terminate comment line.

Below are example of single line comment and multiple line comment in C Programming.

//This is single line comment
/*
Multiple comment line 1
Multiple comment line 2
Multiple comment line 3
…………………
*/

 

Whitespace in C Programming

Whitespace is used in C Program to describe blanks, tabs, newline characters or comments. Whitespace distinguishes two parts of a statement and enables the compiler to identify individual elements of a statement. It can be also use to improve readability of statement code. If there is any line in the program with only whitespace, it will be considered as blank and ignored by the compiler during compilation of the program.

Some Rules of C Programming Basic Syntax

  • C language is a case sensitive language so all the C instructions must be written in lower case. In C language, ‘Csecorner’ and ‘csecorner’ have two different meanings.
  • All statements must end with a semicolon.
  • Whitespace is used in C to describe blanks or tabs. A fully blank line is ignored by the compiler.
  • Whitespace is required between keywords and identifiers. Absence of whitespace between keywords and identifiers  sometime leads to syntax error.
Close Menu