C - Basic Syntax tokens,semicolon,whitespace,etc [1.0.4]

Posted by Parth Makadiya on 12:20 with No comments

Tokens in C


[This Post is important & quite big so read carefully]

A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.
  1. Keywords                (eg: int, while),
  2. Identifiers                (eg: main, total),
  3. Constants               (eg: 10, 20),
  4. Strings                    (eg: “total”, “hello”),
  5. Special symbols      (eg: (), {}),
  6. Operators               (eg: +, /,-,*)
Shortcut To remember this (KISSCO-first letter of everyone)

Keywords:-  Keywords are standard identifiers that have standard predefined meaning in C. Keywords are all lowercase.
The standard keywords are given below:
Keywords
Identifiers:-Identifiers are the names that are given to various program elements such as variables, symbolic constants and functions.Basically Identifiers are the names .

There are some Rules to Define Identifiers

1
.  Name of Identifiers Begins with a Letter (ex . int Parth)
2. It contains A-Z,a-z,0-9,And only one special charcter is allowed and That's "_"(Underscore)
3. Identifier must not keyword .(Ex. It's Wrong to define int printf;)
4No Special Characters are allowed Except "_"

Note:-You cannot Write digit as 1st charcter of Identifiers.
Examples :- 
int Parth;
float Parth_Makadiya;

char Parth12;
string _Parth;

For example, the following C statement consists of five tokens:
printf("Hello, World! \n");
The individual tokens are:
printf
(
"Hello, World! \n"
)
;

Semicolons ;

In C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.
For example, following are two different statements:
printf("Hello, World! \n");
return 0;

Comments

Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminates with the characters */ as shown below:
/* my first program in C */
You cannot have comments within comments and they do not occur within a string or character literals.

White space in C

A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it.
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 enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement:
int age;
There must be at least one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them. On the other hand, in the following statement:
fruits = bananas + strawberry;   // get the total fruit
No whitespace characters are necessary between fruit and =, or between = and apples, although you are free to include some if you wish for readability purpose.