Tokens in C language

Tokens in C

Tokens in C language

Tokens in C language is the most important part to be used in creating a program and The smallest individual element in C is called as Token. Also tokens in C is the building block for creating a program in C. C program consists of tokens these are identifiers, variables, symbols. Tokens is define as the smallest units of a program that convey a specific meaning to the compiler.

The tokens in C language are:

    1. Keywords
    2. Identifiers

    3. Constants

    4. Strings

    5. Special Symbols

    6. Operators

1. Keywords in C

Keywords is defined as the pre-defined and reserved words in a programming language. Every keyword is means to perform a specific function in a program and keyword has its own functionality so keywords are referred names for a compiler, they cannot be used as variable names.we are trying to assign a new meaning to the keyword which is not allowed and cannot be used as the variable names. You cannot redefine keywords. There are 32 keywords they are follows

auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

 

2. Identifiers in C

The identifiers are a collection of alphanumeric characters that start with an alphabetical character or an underscore, which are used to represent different programming elements such as variables, functions, arrays, structures, unions, labels, etc They are user-defined names consisting of an arbitrarily long sequence of letters and digits with a letter or the underscore(_) as a first character. It must differ in spelling and case from any keywords. Once you declared the identifier, you can use it in later program statements to refer to the associated value. A spcific kind of identifier, called a statement label, can be used in goto statements.

There are 52 alphabetical characters and underscore character, and ten numerical digits (0 to 9) that represent the identifiers. There are 63 alphanumerical characters that represent the identifiers

Rules that should be followed while naming c identifiers: 

    • They start with a letter or underscore(_).
    • They consist of only letters, digits, or underscore.
    • Other special character is not allowed.
    • It should not keyword.
    • It not contain white space.
    • main: method name.
    • a: variable name

3. Constants in C

A constant is a value assigned to the variable which will remain the same in the program i.e.the constant value cannot be changed. It refers to fixed values. They are also called literals. It may belong to any of the data types

Syntax

const data_type variable_name;

 

4. Strings in C

Strings are an array of characters ended with a null character. This null character indicates the end of the string and it is always enclosed in double-quotes. Strings are always represented as an array of characters having null character ‘\0’ at the end of the string and this null character denotes the end of the string.

Declaration of string:

    • char string[10] = {‘a’, ’b’, ‘c’, ‘d’, ‘\0’};
    • char string[10] = “abcd”;
    • char string [] = “abcd”;
      when we declare char as “string[10]”, 10 bytes of memory space is allocated for holding the string value.

 

5. Special Symbols in C

 The following symbols are used in C programming

    • Brackets[]: Brackets are used as array element references and they indicate single and multidimensional subscripts.
    • Parentheses(): Parenthesis are used to indicate function calls and function parameters.
    • Braces{}: These braces mark the start and end of a block of code containing more than one executable statement.
    • Comma (, ): Comma is used to separate parameters in function calls.
    • Colon(:): Colon is an operator that essentially call on something called an initialization list.
    • Semicolon(;): Semicolon is also called a statement terminator. The semicolon indicates the end of one logical entity. So, each statement ended with a semicolon.
    • Asterisk (*): Asterisk used to create a pointer variable and for the multiplication of variables.
    • Assignment operator(=): This operator is used to assign the 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 in C

Operators are symbols that trigger an action when applied to C variables and another objects. The data items on which operators act upon are called operands.

 

Also read, Basic Syntax

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *