Tokens

Tokens

A token is the smallest element of a program that is meaningful to the compiler. Given below are the classifications of tokens:

rn

 

rn

Keywords

rn

Identifiers

rn

Constants

rn

Strings

rn

Special Symbols

rn

Operators

rn

 

rn

Keyword: Keywords are pre-defined or reserved words in a programming language. Each keyword is meant for performing a specific function in a program. Since keywords are referred names for a compiler, they can’t be used as variable names because by doing so, we are trying to assign a new meaning to the keyword which is not allowed. Keywords cannot be re-defined. However, you can specify text to be substituted for keywords before compilation by using C/C++ pre-processor directives. 32 keywords are supported in C language.

rn

 

rn

Identifiers: Identifiers are used as the general terminology for naming of variables, functions and arrays. These are user defined names consisting of arbitrarily long sequence of letters and digits with either a letter or the underscore(_) as a first character. Identifier names must differ in spelling and case from any keywords. You cannot use keywords as identifiers; they are reserved for special use. Once declared, you can use the identifier in later program statements to refer to the associated value. A special kind of identifier, called a statement label, can be used in goto statements.

rn

 

rn

Rules to be followed while naming C identifiers:

rn

They must begin with a letter or underscore(_).

rn

They must consist of only letters, digits, or underscore. No other special character is allowed.

rn

It should not be a keyword.

rn

It must not contain white space.

rn

It should be up to 31 characters long as only first 31 characters are significant.

rn

 

rn

Constants: Constants are also like normal variables. But, only difference is, their values can not be modified by the program once they are defined. Constants refer to fixed values. They are also called as literals.

rn

 

rn

Strings: Strings are nothing but an array of characters ended with a null character (‘’).This null character indicates the end of the string. Strings are always enclosed in double quotes. Whereas, a character is enclosed in single quotes in C and C++.

rn

 

rn

Special Symbols: The following special symbols are used in C having some special meaning and thus, cannot be used for some other purpose.[] () {}, ; * = #

rn

Brackets[]: Opening and closing brackets are used as array element reference. These indicate single and multidimensional subscripts.

rn

Parentheses(): These are used to indicate function calls and function parameters.

rn

Braces{}: These opening and ending curly braces marks the start and end of a block of code containing more than one executable statement.

rn

comma (,):  Used to separate more than one statements like in for loop is separates initialization, condition and increment.

rn

semi colon : It is an operator that essentially invokes something called an initialization list.

rn

asterick (*): It is used to create pointer variable.

rn

assignment operator: It is used to assign values.

rn

pre processor(#): The pre processor is a macro processor that is used automatically by the compiler to transform your program before actual compilation.

rn

 

rn

Operators: Operators are symbols that triggers an action when applied to C variables and other objects. The data items on which operators act upon are called operands.

rn

Depending on the number of operands that an operator can act upon, operators can be classified as follows:

rn

Unary Operators: Those operators that require only single operand to act upon are known as unary operators. For Example increment and decrement operators.

rn

Binary Operators: Those operators that require two operands to act upon are called binary operators. Binary operators are classified into:

rn

Arithmetic operators

rn

Relational Operators

rn

Logical Operators

rn

Assignment Operators

rn

Conditional Operators

rn

Bitwise Operators

rn

 

rn

 

c