Tokens in C Programming | Programming Tutorials | Programming concepts

HELLO, guys  our last blog was regarding Variable and Variable Declaration, now in this blog we will learn about  TOKENS in C Programming Language.

TOKENS  are the smallest part of a C program  which cannot be further subdivided.It is each and every word and punctuation that you come across in C program. The compiler breaks a program into the smallest possible units (tokens) and proceeds to the various stages of the compilation.

In a C program ,there are  7 types of TOKENS -:

1.Identifiers(program specific words)                    
2.Reserved Words(language specific  words)
3.Separators
4.Comment lines
5.Special Symbols / Punctuation symbols
6.Operators
7.Constants 


1. RESERVED WORDS-
These are some pure-defined words which comes with the language.They have specific use inside the program.
Example: include,main, NULL,ETC.


Keyword is a subset or parts of RESERVED WORDS.There are 32 keywords but day by day new keywords are getting added.
Example: LATEST C-17, C-11,C-99 ,ETC.
All the keywords should be in small case letters.


Following table represents the keywords in 'C'-
autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constshortfloatunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile



2. IDENTIFIERS-
These are some names corresponds to a variable , array , function, structure , union, file , etc.

RULES FOR  NAMING AN IDENTIFIERS:
1. The identifiers name should begin with underscore ' _ ' or with an English alphabet .
Eg: _ab, abc, a,x,etc.

2.There should not be any space or tab in the name of the identifier.

3.It is case sensitive.

4.Identifier name should not be a keyword but we can have identifier which may be equal to a reserved word.

5.Identifier name should not contain any special character except underscore(_).


3.SEPARATORS-
Space, tab & letters they all are known as SEPARATORS.They make the program meaningful. Space, tab and enter are  known as whitespace.

 
4.COMMENT LINES-
This is a kind of extra or optional or additional information about the program i.e.the programmer name,date of modification,about the logic of the program,etc.

They are 2 types of comment lines :-

1.Single line Comment that starts with " /* " and ends with the same, it has both beginning mark and the ending mark.

2.Multi-line Comment that starts with " // ", it has only beginning mark and not an ending mark.


5.SPECIAL SYMBOLS

The following special symbols are used in C having some special meaning and thus, cannot be used for some other purpose.[] () {}, ; * = #
  • Brackets[]: Opening and closing brackets are used as array element reference. These indicate single and multidimensional subscripts.
  • Parentheses(): These special symbols are used to indicate function calls and function parameters.
  • Braces{}: These opening and ending curly braces marks the start and end of a block of code containing more than one executable statement.
  • comma (, ): It is used to separate more than one statements like for separating parameters in function calls.
  • semi colon (; ): It is an operator that essentially invokes something called an initialization list.
  • asterick (*): It is used to create pointer variable.
  • assignment operator: It is used to assign values.
  • pre processor(#): The preprocessor is a macro processor that is used automatically by the compiler to transform your program before actual compilation.


6.OPERATORS-

Operator is a symbol or a set of symbol which is used to perform an operation.

An operator can be classified based upon the following factor.
 
1. Arity
2. Associativity
3. Precedence
4. Usages



7.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.

Constants may belong to any of the data type.
Syntax:

const data_type variable_name; (or) const data_type *variable_name;

The several Types of Constants are:

  1. Integer constants – Example: 0, 1, 1218, 12482
  2. Real or Floating point constants – Example: 0.0, 1203.03, 30486.184
  3. Octal & Hexadecimal constants – Example: octal: (013 )8 = (11)10, Hexadecimal: (013)16 = (19)10
  4. Character constants -Example: ‘a’, ‘A’, ‘z’
  5. String constants -Example: “TechSutra”




   HOPE , You all enjoyed learning about TOKENS in detail.If you have any suggestion / Advice for us ,feel free to tell us in the comment section or you can Email us. You may also ask your doubts in comments section.
We will be happy to know your feedback.Also , your feedback will help us to improve and motivate us to add more to this blog.

Till then,Stay safe & stay healthy.Have a nice day!!!








Comments