What is tokens in C language - Code Is Interest

C Tokens :


The smallest individual elements or units in a program are called Tokens. C has the following tokens.
  • Identifiers
  • Keywords
  • String
  • Constants
  • Operators
1. Identifiers:
Identifiers are the names that are given to various program elements such as variables, symbolic constants, and functions.
Rules for defining an Identifiers:
  • An identifier can only have alphanumeric characters (a-z , A-Z , 0-9) (i.e. letters & digits) and underscore( _ ) symbol.
  • Identifier names must be unique.
  • The first character must be an alphabet or underscore.
  • You cannot use a keyword as identifiers.
  • Only the first thirty-one (31) characters are significant.
  • Must not contain white spaces.
  • Identifiers are case-sensitive.
Example :

some legal identifiers:

float _number;
float a;
int this_is_a_very_detailed_name_for_an_identifier;

-This type of identifier you should use in your programming. 

The following are illegal identifiers: 

float :e;
float for;
float 9PI;
float .3.14;
float 7g;
Float firstname

-This type of identifier you should not use in your programming (Not acceptable).

2. Keywords :

  • Keywords are standard identifiers that have standard predefined meaning in C. 
  • Keywords are all lowercase, since uppercase and lowercase characters are not equivalent it’s possible to utilize an uppercase keyword as an identifier but it’s not a good programming practice.

Points to remember

1. Keywords can be used only for their intended purpose.

2. Keywords can’t be used as programmer-defined identifiers.

3. The keywords can’t be used as names for variables.

Keyword in c language:

  • auto, double, int, struct, break, else, long, switch, case, enum, register, typedef, char, extern, return, union, etc.....
3. String
  • Strings in c is an array of characters having null characters‘\0’ at the end of the string. Strings in c are enclosed in double-quotes(“”) and characters are enclosed in single-quotes('').

char a[5]={'1','2','3'};
char a[]="yash";
char a[5]="nishit";

4. Constants
  • A character constant is a single character, enclosed in single quotation marks.
  • e.g., ‘A’  ‘B’ ‘1’
For more click here:- Type of Constant

5. Operators

  • The symbols which are used to perform logical and mathematical operations in a C program are called C operators.
  • These C operators join individual constants and variables to form expressions.
  • Operators, constants, and variables are combined together to form the expressions.
  • Consider the expression A + B * 5. 
Where, +, * are operators
    A, B  are variables
    5 is constant and
    A + B * 5 is an expression.
For more click here:- Type of Operators

Post a Comment

0 Comments