Well, now we have seen the basic structure of the C program that will help us in learning the syntax of the C language easily.
Tokens in C
C program includes various types of tokens like keyword, identifier and constants, etc.
Here is an example.
printf("Hello World! \n"); |
This example consists of 5 tokens. The following tokens are-
printf ( "Hello World! \n" ) ; |
Semicolons
The semicolon is a statement terminator in a C program, which means each statement in the C language should end with a semicolon. The semicolon indicates the end of the statement. Your code will pop an error if you will not use this semicolon in the last of the statement.
Here is an example of the semicolons-
printf("Hello World! \n"); return 0; |
Comments
If you want to label any line of code in the C program, you have to use comments because comments are the only one which is ignored by the compiler. The syntax to write a comment is as follows-
/* my first Hello World program in C */ |
A comment starts with "/*" and ends with "*/"
Identifiers
The identifier in C is a name used to identify a variable function or any other item in the C program. Identifier starts with alphabets, underscores "_" and digits(0-9).
The C language does not allow any type of punctuation characters like"@, &, %, etc". This is why C is a very case sensitive programming language.
Here are some examples of identifiers-
abcd rrtutors abc c_language a_13
myname0 _temp p a29 programming
Keywords
The keywords are the reserved words that are used in the C language for initializing different variables or identifiers in C.
goto |
do |
enum |
volatile |
return |
static |
register |
typedef |
char |
int |
break |
while |
const |
float |
unsigned |
_Packed |
if |
for |
signed |
long |
else |
auto |
sizeof |
switch |
void |
struct |
case |
short |
default |
extern |
continue |
union |
double |
|
|
Whitespace in C language
A line that contains the only whitespace is known as a blank line which is also ignored by the compiler.
Whitespace is usually used in C to define blanks, newlines and comments. Also, whitespace also divides the variable from keywords and explains to the compiler which one is a keyword or which one is a variable. Here is an example to explain my words.
int rollNo; |
There must be a space between int and rollNo which helps the compiler to distinguish between them.
fruit = apples + oranges; // To calculate the total fruit
We have used whitespace several times in the above program that helps the compiler to identify.
Whitespace is not necessary between "fruit" "=" "apples" "+" "oranges" in the above line. The compiler is quite intelligent to identify this line.