Download tokens in c programming language and more Slides Public Law in PDF only on Docsity!
C- Tokens
Prepared by Santosh Kumar Sharma
Token
(^) C tokens are the basic buildings blocks in C language which are constructed together to write a C program.
(^) Each and every smallest individual units in a C program are known as C tokens.
(^) C tokens are of six types. They are,
Keywords (eg: int, while),
Identifiers (eg: main, total),
Constants (eg: 10, 20),
Strings (eg: “total”, “hello”),
Special symbols (eg: (), {}),
Operators (eg: +, /,-,*)
Continue…
(^) C language supports 32 keywords which are given below.
Identifiers
(^) Each program elements in a C program are given a name called identifiers.
(^) Names given to identify Variables, functions and arrays are examples for identifiers. eg. x is a name given to integer variable in above program.
(^) These are user defined names and consist of sequence of letters and digits with a letter as a first character.
C- Constants
(^) C Constants are also like normal variables. But, only difference is, their values can not be modified by the program once they are defined.
(^) Constants refer to fixed values. They are also called as literals
(^) Constants may be belonging to any of the data type.
Types of C-constant
(^) Integer constants
(^) Real or Floating point constants
(^) Octal & Hexadecimal constants
(^) Character constants
(^) String constants
(^) Backslash character constants
Rules for constructing integer
constants
(^) An integer constant must have at least one digit.
(^) It must not have a decimal point.
(^) It can either be positive or negative.
(^) No commas or blanks are allowed within an integer constant.
(^) If no sign precedes an integer constant, it is assumed to be positive.
(^) The allowable range for integer constants is -32768 to 32767.
Rules for constructing real constants
(^) A real constant must have at least one digit
(^) It must have a decimal point
(^) It could be either positive or negative
(^) If no sign precedes an real constant, it is assumed to be positive.
(^) No commas or blanks are allowed within a real constant.
Rules for constructing backslash
constants
(^) There are some characters which have special meaning in C language.
(^) They should be preceded by backslash symbol to make use of special function of them.
(^) On next slide the list of special characters and their purpose is given.
Continue…
(^) A variable is a data name that may be used to store a data value.
(^) Unlike constants that remain unchanged during the execution of a program, a variable may take different values at different times during execution.
(^) A variable may be chosen by the programmer in a meaningful way so as to reflect its functions or nature in the program.
Rules for constructing
variable
(^) Variable name must begin with letter or underscore.
(^) Variables are case sensitive.
(^) They can be constructed with digits, letters.
(^) No special symbols are allowed other than underscore.
(^) It should not be any keyword.
(^) White space are not allowed.
(^) For Example: san, T_value, x1, Del, etc..
Integer Types
(^) Integers are the whole numbers with a range of values supported by particular machine.
(^) Generally, integers occupy one word of storage and since the word sizes of machines vary (16 bits or 32 bits) the size of an integer that can be stored depends on the computer.
(^) If we use a 16 bit word length, the size of the integer value is limited to the range -32768 to +32767.
(^) A signed integer uses one bit for sign and 15 bits for magnitude for the number.
(^) Similarly, a 32 bit word length can store an integer ranging from – 2147483648 to + 2147483647.