Tokens in c

What are the tokens in c language?

Tokens are the smallest elements used to build a program in c.

Tokens can be classified into six types. They are as follows:

  • Keywords
  • Constants
  • Identifier
  • strings
  • Special symbols
  • Operaters

Let us see one by one.

Keywords

Keywords are also known as “Reserved words”. They have special meaning when used in a program.

For example int is a reserved keyword in c which is used to store integer type variable values.

There are total 32 keywords are there in c.

C Keywords are as follows:

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constfloatshortunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile

Constants

Constants are fixed values. Their values can not be altered during execution. Constants are also known as literals.

There can be an integer constant, a floating constant, a character constant.

Types of constants are as follows:

Integer constant

It can be a decimal, hexadecimal, octal constant. A prefix defines the base.

Example:212,21u,0x3c,……

Floating point literals

It can be in decimal form or exponential form. It has an integer part, a decimal point, a fractional part, an exponent part.

For example: 3.14,32E,….

Character constants

The character constant is enclosed in single quotes. It is stored in char type variable.

For example: ‘a’,’\n’,…..

String constants

These are enclosed in double quotes. It contains set of characters.

For example: “scholarsoul”,”1234″,…..


Identifier

It is a name used to identify a variable, function, structure, array, union….

C Keywords can not be used as identifiers but it can be the part of identifier.

For example: abc, number,….

Rules for naming identifiers in c

  • Identifier must begin with underscore or alphabet.
  • It must not contain whitespace.
  • It should not be a keyword.
  • Special characters are not allowed.

Strings

It is a set of characters terminated with a null character.

It is enclosed in a double quotes.

For example:”scholarsoul”, “cprogram”,….


Special symbols

C provides special characters to be used along with letters and numbers.

For example: !,@,#,%,&,*,(,),…..

There are total 30 special characters in c.


Operators

These are special symbols used for mathematical operations. Consider two integer variables a and b.

Following are the types of operators

  • Arithmetic operators: C provides arithmetic operators to add, substract, divide, multiply, increment, decrement values. For example: a+b, a-b, a/b,…….
  • Relational operators: It is used to compare two values like >=,<=,==,!=,>,<. For example a>b, a<b,…..
  • Logiacal operators: It is used to compare two values. For example a&&b, a||b, !(a||b).
    i. Logical AND(&&): If both a and b operands is non-zero then result is true otherwise result becomes false.
    ii. Logical OR: If anyone of a and b operands are non-zero then result becomes true.
    iii. Logical NOT: It is used to reverse the logical state of its operand.
  • Bitwise operators: These operators works on bits.
  • Assignment operators: It is used to assign values to variables. example a=0,a+=10,a-=1,a/=10,a*=10.

Truth table

aba & ba | ba ^ b
00000
01011
11110
10011

People also ask for

What are tokens in c?

Tokens are the smallest elements used to build a program in c.

What is keyword in c?

Keywords are also known as “Reserved words”. They have special meaning when used in a program.