C Tokens in C Programming Language

What is C Token in C Language? 

The smallest building unit or block of a C program is termed as C Tokens. Compiler of C program uses to break a program into the smallest possible units to proceeds to the various stages of the compilation. Every word and punctuation are tokens in C. C Programming language has 6 types of tokens. These are:

  1. Keywords
  2. Identifiers
  3. Constants
  4. Strings
  5. Special Symbols
  6. Operators

 

C Tokens in C Programming Language

a) Keywords:

Every C-word is classified as a keyword or identifier. Keywords have meaning. Examples of keywords are float, while etc. Keywords serve as basic building units for statements. C Programing Language has a total 32 keywords. List of the keywords are:

Serial No

Keywords

01

auto

02

break

03

case

04

char

05

const

06

continue

07

default

08

do

09

double

10

else

11

enum

12

extern

13

float

14

for

15

goto

16

if

17

int

18

long

19

register

20

return

21

short

22

signed

23

sizeof

24

static

25

struct

26

switch

27

typedef

28

union

29

unsigned

30

void

31

volatile

32

while

 


b) Identifiers:

Identifiers are those types of words written in C which is the name of variables, functions or arrays. These are user-defined names and consist of digits and letters. But the name of identifiers has to be followed by some rules. These rules are:

  • First Character must be a letter or underscore, cannot be a number
  • Must consist of only letters, digits, or underscore.
  • Significant characters are only the first 31 characters
  • Keywords cannot be used as an identifier
  • No white space is valid.

 

c) Constants:

Constants are fixed values. Constants do not change, just like math. Constants of C Programming Language can be divided into 5 subclasses under 3 class. They are:

  1. Numeric Constants: Integer Constance and Real Constants
  2. Character Constants: Single character constants and String Constants.
  3. Special Output Constant: Backslash Character Constant.

 

1. Integer Constants

Integer Constant refers to a sequence of digits and there are mainly 3 types of integers. Integers in C Programing are:

  1. Hexa-Decimal Integer
  2. Decimal Integer
  3. Octal Integer

It can have numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and a + or - sign. Using these positive or negative signs is not compulsory.

Some integer constants are 71, 0249, -273, +2441136666100, 0

As they can be Decimal, Octal and Hexadecimal then we are giving more examples for those.

  • Decimal Integer Constant: +7149
  • Octal Integer Constant: +156
  • Hexadecimal Constant: 0X9D

Note about hexadecimal constant: Sequence of digits preceded by 0x or 0X is considered as a hexadecimal integer, and A to F can be used in uppercase or lowercase as the programmer wants.

Convert Numbers from Decimal to Octal or Hexadecimal by clicking here.

 

2. Real Constants:

Every constant made by real numbers is a real integer except the Constant is an integer constant. For example, 0.95, 0.0083, +247.0, +6e7, 3.0249E3.

 

Exponential notation is useful sometimes useful for representing numbers that are either very large or very small. For instance, 4900000000 can be written as 4.9E9 or 49E8.

Let find some valid and invalid constants from the Numeric Integer.

Constant

Valid or Not?

24411875

Valid

100D

Valid

25,000A

Invalid

7.1e 2

Invalid (space doesn’t allow)

0X7B

Valid

$71

Invalid

+5.0A2

Valid

 

3. Single Character Constant:

When a single character is being used as a constant then that is called a single character constant. Some examples are ‘5’, ‘X’, ‘ ‘.

Yes, this blank space is also a single character constant.

 

4. String Constants:

A string constant is a sequence of characters that are enclosed in double-quotes. The constants may be letters, special characters, numbers, and blank spaces.

Some examples of String Constants are: “TechKib!”, “Hello!”, “1971”, “PATHGRIHO NETWORK”, “!..?”,  “2+3”, “H”.

Note: A single character string constant does not have an equivalent integer value while a character constant has.

 

5. Backslash Character Constants:

C Programming Language has some special backslash characters constants that are being used for output. The example of backslash characters constants is mentioned below with their function.

Backslash Constants

Function

‘\a’

Audible alert

‘\b’

Backspace

‘\f’

Form-feed

‘\n’

Newline

‘\r’

Carriage return

‘\t’

Tab (horizontal)

‘\v’

Tab (vertical)

‘\”

Single quote

‘\’’

Double quote

‘\?\

Question mark

‘\\’

backslash

 

d) Strings:

Nothing but an array of characters that ended with a null character is termed as a string. This null indicates the end of the string. Null character denotes by ‘\0\.  Some declarations for string are:

  • Char string [20] = “techpathgrihos”;
  • Char string [] == “techpathgrihos”;

This type is also used in C++.

 

e) Special Symbols:

Following special symbols are used in C and they have their own meaning and function. Look at those below:

Symbol

Name

Function

{}

Braces

Indicates the start and end of a unit of a code.

[]

Brackets

Used as an array element reference.

()

Parentheses

These symbols are used in order to indicate calls and function parameters.

,

Comma

Used to separate more than one statement.

:

Colon

Called an initialization list

;

Semicolon

Statement Terminator

#

Pre-Processor

Learn details about Preprocessor by reading the linked article.

=

Assignment Operator

Used to assign values

*

Asterisk

Used to create a pointer variable.

 

f) Operators:

Operators are those who trigger an action when that is applied to C variables as well as other objects. Depending on the number of operands that an operator can do or act, operators can be classified into 2 divisions. Operands are those data on which operators act upon.

 

  • Unary Operators: The operators which require only a single operand to act. For instance, the increment and decrement operators are unary operators.
  • Binary Operators: Operators that require two operands to act are termed as binary operators. Binary operators can be classified into 6 more classes. They are:

    1. Arithmetic Operators (+, -, *, /, %)
    2. Relational Operators (==, >, <, !=, >=, <=)
    3. Logical Operators (&&, ||, !)
    4. Assignments Operators (=, +=, -=, *=, /=, %=)
    5. Conditional Operators  
    6. Bitwise Operators (&, |, ^, ~, <<, >>)

Md. Rabiul Mollah

Okay! So here I'm Md. Rabiul Mollah from Pathgriho Network. I'm currently a student of B.Sc in Textile Engineering Management at Bangladesh University of Textiles. facebook instagram github twitter linkedin

Post a Comment (0)
Previous Post Next Post