C tokens

Tokens

A token is nothing but a smallest individual component in a program. C language contains the following tokens:
1.Keywords
2.Identifiers
3.Constants
4.Strings
5.Special symbols
6.Operators

1.Keywords

Keywords have fixed meaning and this meanings can not be modified. The meaning of the keyword is already defined by the compiler. Keyword are nothing but reserved words. Each and every keyword has it's unique importance in the program. All keywords are written in lower case.
The list of keywords are given below

break                  else                auto                      struct
case                    enum             register                type def
char                    extern            return                   union
const                   for                  short                    void
continue             goto               signed                  main    
default                 if                    sizeof                   unsigned
do                        int                   static                    volatile
double                float                switch                  long

2.Identifiers

Identifiers are the names which are declared by the users for application requirement
Limitations:
  • It must begin with an alphabet or an underscore( _ )
  • It's length should not cross more than 32 characters
  • It may be in upper or lower or mixed case
  • It may have digits
  • It may have special characters
  • It should not be a keyword
Example:
Identifier               Valid or Invalid
_abc                             valid
abc                               valid  
AbcD                            valid
SBC                              valid
abc1                              valid
1abc                              invalid   //should not start with digits
int                                  invalid //it should not be a keyword

3.Constants

Constants are similar to variables but here the values can not be changed that is nothing but the vales are fixed and can not be modified. Constants are also known are Literals.


Integer constant: 
      This refer to sequence of digits.They are classified into following types
i.Decimal: Decimal integer constant contains set of digits from 0 to 9 which can also be presided with + or -
Example: +999, -999, 999
ii.Octal: Octal integer constant contains set of digits from 0 to 7 with leading 0.
Example: 076, 0777
iii.Hexadecimal: Hexadecimal integer constant contains set of digits from 0 to 9 and A to F or a to f.
Example:999, a58
Real constant:
       Real constants are also called as floating point constants.Here fractional parts are also considered.
example:9.8
Single character constant
      This are enclosed in a pair of single quotation marks( ' ')
Example: 'i', 'n', 't', 'e', 'r', 'v', 'i', 'e', 'w', 'c', 'o', 'd', 'i', 'n', 'g', 'p', 'r', 'e', 'p'
String constant: 
      This are enclosed in a pair of double quotation marks(" ")
Example:"interviewcodingprep", "coding"

4.Strings

A string is a collection of group of characters.A string is ended with a null character ( \0 ) which indicates the end of the string.
Strings are enclosed in a pair of double quotes (" ").
Example:
char ch[30]= "interviewcodingprep" // a valid string.
char ch[]={'i','n','t','e','r','v','i','e','w','c','o','d','i','n','g','p','r','e','p','\0'} //valid

5.Special symbols

In C we have some special symbols with special meaning and this symbols cannot be used for some other purpose.Those are given below
  • Brackets[]:  Used for array element reference which indicate single and multidimensional subscripts.
  • Parentheses(): Indicate function calls and function parameters.
  • Braces{}: Indicates the start and end of a block of code containing more than one executable statement.
  • comma (, ): Used to separate more than one statements or value.
  • semi colon(;) : Indicates initialization list.
  • asterick (*): Used to create pointer variable.
  • assignment operator: Used to assign values.
  • pre processor(#): The preprocessor is a macro processor.This is used automatically by the compiler.

6.Operators

Operators are symbols used to perform the operation on the opponents.
Operators are classified into following ways:
  1. Unary operator
  2. Binary operator

Unary operator:

An operator which is used to perform operations on a single operand is known as unary operator.
Example: Increment operator and decrement operator

Binary operator:

An operator which is used to perform operations on a two or more operands is known as unary operator.
Binary operators are of following types:
  1. Arithmetic operators
  2. Relational Operators
  3. Logical Operators
  4. Assignment Operators
  5. Conditional Operators
  6. Bitwise Operators
  7. Special Operators


No comments:

Post a Comment