Tokens in C

Tokens in C


Tokens are called building block of C programming, that means only with the help of tokens a C program can be created.

  • every small part that is used in the program is called tokens.
  • In C programming, some INDIVIDUAL words and characters are fixed, whose functions are fixed, called tokens.
  • It is the smallest element of C program.

There are some internal tokens we need to know while writing a program in C to understand the most basic to the syntax of the C language.

Some internal tokens are:-

  • Keywords
  • Identifiers
  • Constants
  • Strings
  • Special Symbols
  • Operators

for example, look at the program below. this program is used in the correct order of tokens.

 #include<stdio.h>
 int main()
 {
printf("my name is somya");
printf("%d",4);
}
tokens

KEYWORDS

Keywords are predefined statements ,operators reserved words which have a special meaning to the compiler while execution, they are a part of it and can not be used as an identifier. C language provides 32 keywords. every keyword has a special meaning. each keyword is defined to do a specific job. Here is a list of some identifiers given below

autoelselongswitch
breakenumregistertypedef
casedoublereturnunion
charfloatshortunsigned
constforsignedvoid
continuegotosizeofvolatile
defaultifstaticwhile
dointstruct_Packed
  

IDENTIFIERS

In a simple language an identifier is the name of a variable (integer,float(decimal),character) given to a variable or constant for a program just like a math problem. It can start anywhere from A to Z or a to z or underscore ( _ ) and you may or may not add more to the later by integer digits or more letters or underscores .

But one should always remember that C is a case-sensitive programming language .So identifiers like Goku, goku, _goku, goku1 ,Goku1 are all different identifiers .

Note : C doesn’t allow punctuation’s like ! @ $ % & * in identifiers so make sure you don’t have a [email protected] or goku! named identifier .

Identifiers are the names that give you variables,constants and functions. these are some rules to give to these names that you follow, if you don’t follow then there is an error in the program.  

  • In Identifiers @, %, -characters can not be used.
  • C is a Case sensitive language, So more and More both are said to be different identifiers.
  • In Identifiers, we can not use operators.
  • It can start anywhere from A to Z or a to z or underscore ( _ ) and you may or may not add more to the later by integer digits or more letters or underscores.
  • you can either start an identifier with either a character or underscore. Digits can not be started from identifiers.

Example:-

_old         //identifier
2name    //not identifier
person-name   //not identifier
person_2_old       //identifier.

CONSTANTS

Constant is a value, which does not change in program execution. 

  • constant value is fixed. 
  • it is also known as Literals.
  • it does not matter where we use it in program,its meaning always fixed.
  • it is also like normal variables.

Types of Constants:-

       1.Integer constant -The whole values used in the C program are called integer constant.

          Like: 1,53,677 e.t.c.

       2.Character constant – The different characters used in the C program are called character constant. 

          Like: f, v, s, w, # e.t.c.

       3.Float constant – In C program, such numeric value in which the digit after the decimal is called float constant.

          Like: 4.44444, 34.6634 etc.

       4.String constant – many literal characters are placed under string literal.

          Like: “rat”, “prep”,etc.

STRINGS

The group of characters is known as strings. which are always enclosed in double quote. it is also said to be array of characters.it is used to stored data of class,mobile numbers , name etc. At the end of the string there is always a special character, which is known as null. its indicate the end of the string.

Declaration of Strings:-

char string[20] = {‘p’,’r’,’e’,’p’,’I’,’n’,’s’,’t’,’a’,’\0′};

char string[20] = “prepInsta”;

char string[] = “prepInsta”;

SPECIAL SYMBOL:-

Some special symbols are used in C programming. symbols means alphabet, exclude the digits using some symbols in C programming.In C programming some special symbol are used in C having some special meaning and cannot be use in other purpose.

The following symbols are:-

Braces {}:- these curly braces are used to show the starting and ending of a block of code containing some executable statement.

Parentheses ():- Parentheses are used to specify the function call and function parameter.

Brackets []:- this is the opening and closing brackets. it is used as array element reference. these stipulate the single and multidimensional subscripts.

Comma (,) :- it is used to separate more then one statement.

Asterick (*) :- used to create pointer variable.

Assignment variable:- used to assign values.

Semicolon:- In C program after every statement we have to put a semicolon (;) which tells the compiler the statement ends there .For example

 printf("Kamehameha");
return 6;

It indicates the end of one logical entity.

OPERATORS

Operators is special symbol which is used to perform mathematical operation like, addition, subtraction, division, multiplication.Different types of symbols are used to perform different type of mathematical and logical operation in C programming is known as operators. that symbols. 

types of operator:-

  1. Unary Operator:– unary operators are those operators, which require only single operands is known as unary operator.

          Example:- increment and decrements operator.

      2. Binary Operator:- Those operators, which require two operands is known as binary operator.

Binary operators are:

  • Arithmetic operator
  • Logical operator
  • Bitwise operator
  • Conditional operator
  • Relational operator
  • Assignment operator

      3.Ternary operator:- These operators which require three operands are known as ternary operator.

         Example:– Conditional operator (?:).

 

7 comments on “Tokens in C”