C Language Syntax Rules
C Language Syntax Rules
Like any other natural language, a computer language also follows some syntax rules. All the statements written in a computer language must follow all the syntax rules imposed by that language.
If these rules are avoided then the computer program will never be compiled and executed.
Every computer language has different set of syntax rules. Luckily C has a very few syntax rules. To understand the syntax rules of C language, consider the following C program.
Syntax Rules
- C is a case sensitive language which means that if a statement is required in lowercase then it cannot be written in capital letters. For example, at line 3 above, we can see that void is written in small letters. If we write it as Void or VOID then it will not be recognized by the compiler and error message will be generated. Most of the C statements are written in small letters but it is not a rule. Some statements can be written in capital letters as well (to be discussed in later tutorials).
- All the statements must be terminated by a semi colon. As we can see at lines 6 and 9, the statements are terminated by semicolon.
- Whitespace characters (space or tab) are required between two words or statements.
Important
- Although this is not a rule but important to note that almost every C program starts with header file. A header file is a set of predefined functions.
- We must include the header file having the function to be used in the current program. In the above program, line 1 and 2 shows that how the header files are included by using the #include preprocessor.
- Comments are very commonly used in every computer program to show the purpose of whole program or the purpose of a particular step or statement.
- We can write the comments in a single line or the comments may spread over multiple lines. Single line comments are demonstrated at line 5 and multiple line comments are shown at lines 7-8 in the example above.