Tokens in C

 

Character Set of C

The C Character Set

Character set is set of valid characters that a language can recognise. A character represents any letter, digit, or any other sign that can be used in a program.

Category

Character Set

Lowercase & Uppercase Letters

a-z, A to Z

Digits

0-9

Special Characters

,.;:`?!&^*-+<>()|\~-$?[]()%#=@

White Spaces

Tab, space, newline

Tokens In C

A token is the smallest element of a program that is meaningful to the compiler. Tokens can be classified as follows:

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

Keyword

Keywords are pre-defined or reserved words in a programming language. Each keyword is meant to perform a specific function in a program. Since keywords are referred names for a compiler, they can’t be used as variable names because by doing so, we are trying to assign a new meaning to the keyword which is not allowed. You cannot redefine keywords. C language supports 32 keywords which are given below:

auto

else

long

switch

break

enum

register

typedef

case

extern

return

union

char

float

short

unsigned

const

for

signed

void

continue

goto

sizeof

volatile

default

if

static

while

do

int

struct

double

Identifiers

Identifiers are used as the general terminology for naming of variables, functions and arrays. These are user defined names consisting of arbitrarily long sequence of letters and digits with either a letter or the underscore(_) as a first character. Identifier names must differ in spelling and case from any keywords. You cannot use keywords as identifiers; they are reserved for special use. Once declared, you can use the identifier in later program statements to refer to the associated value. A special kind of identifier, called a statement label, can be used in goto statements.

 Rules for naming c identifiers

  1. They must begin with a letter or underscore(_).
  2. They must consist of only letters, digits, or underscore. No other special character is allowed.
  3. It should not be a keyword.
  4. It must not contain white space.
  5. It should be up to 31 characters long as only first 31 characters are significant.
Constants:

Constants in C refer to fixed values that do not change during the execution of a program. Several types of constants supported in C are shown in the chart below

 Constants in C

StringsStrings are nothing but an array of characters ended with a null character (‘\0’).This null character indicates the end of the string. Strings are always enclosed in double quotes. Whereas, a character is enclosed in single quotes in C.

·       char string[15] = {‘p’, ’r’, ‘o’, ‘g’, ‘r’, ‘a’, ‘m’, ‘m’, ‘i’, ’n’, ‘g‘,’\0’};

·       char string[20] = “programming”;

·       char string [] = “programming”;

Operators: An operator is a symbol that tells the computer to perform certain mathematical or logical manipulation on data stored in variables. The variables that are operated are termed as operands. C operators can be classified into 8 types. These operators are given below.

1.

Arithmetic operators

+.-.*,/,%

2-

Assignment operators

=

3.

Relational operators

<,<=,>,>=.= =,!=

4.

Logical operators

!,&&, | |

5.

Conditional operators

? :

6.

Increment and decrement

++,--

7.

Bitwise operators

!,&,|,~,^ ,<<,>>

8.

Special operator

sizeof  , (comma)


Special Characters

The following special symbols are used in C having some special meaning and thus, cannot be used for some other purpose.[] () {}, ; * = #

Brackets[]: Opening and closing brackets are used as array element reference. These indicate single and multidimensional subscripts.

Parentheses(): These special symbols are used to indicate function calls and function parameters.

Braces{}: These opening and ending curly braces marks the start and end of a block of code containing more than one executable statement.

comma (, ): It is used to separate more than one statements like for separating parameters in function calls.

semi colon : It is an operator that essentially invokes something called an initialization list.

asterisk (*): It is used to create pointer variable.

assignment operator: It is used to assign values.

pre processor(#): The preprocessor is a macro processor that is used automatically by the compiler to transform your program before actual compilation.


Comments

Popular posts from this blog

DBMS - Program 6 - Insurance Database

Types of Addressing modes

Java - Swing