Tokens In C Language

Tokens in C Language 

In C Language, Tokens are the part of program which are smallest elements and by collecting these smallest elements every program is designed and developed. 

Types of Tokens in C Language


Tokens in C Language
Tokens in C Language
Keywords- Reserve words, Predefined and having special meaning.
For an example int is a keyword:- 
  1. which is already reserved means we can not create it for different purpose.
  2. which is predefined means we can not redefined it else program generate error.
  3. which is having special meaning to compiler to allocate 2 Byte memory and contain only integer values means we can not create it for floating values.
Here is a List of 32 Keywords in C Language-

auto break case char const
default storage class for a variable used to stop the loop or iteration use to create cases in switch data type for character values use to define constant value
continue default do double else
used to continue the loop or iteration used for default case in switch used with do...while loop data type to store larger value than float used with if and alone is not allowed
enum extern float for goto
used for enumeration user defined structure external or global storage class data type to store floating values used to create for loop used for jumping to label
if int long register return
used for conditional statement integer data type to hold integer values Larger range Modifier to create register storage class variable to return value or stop program
short signed sizeof static struct
smaller range modifier ability to allow negative and positive values operator used to show location size of variable to create single copy of variable to create structure user defined data type
switch typedef union unsigned void
used with cases and perform switch statement define the user defined type name for predefined data type used to create union user defined data type ability to allow only positive values used as nothing return type
volatile while
value may change at any time used to create while loop or iteration

Identifiers 

Identifiers used for naming the constant, variable, function, pointer, struct etc. To create an identifiers we must follow some thumb rules otherwise errors will be generated in C Programming these rules are given below- 

1. It should not be reserve word (Keyword).

2. White Space is not allowed in Identifiers.

3. Only alphabets(a-z,A-Z), digits(0-9) and only underscore( _ ) special symbol is allowed.

4. Identifiers not allowed to start with digits.

5. Special symbols are not allowed except underscore( _ ).

Constant/ Literal

constant are the fixed values and it can assigned to other(ex. int a=10;) but can not take other values to assigned ( ex. int 5=20;) otherwise compiler will generate error. It may be numeric or character based. It can also further classified like integer and floating constant values are numeric constants while single character or literal string constant values are character constants.

Numeric Constant 

integer constant- it can be Decimal (example: 5,10 etc.), Octal (starts with 0 example: 010,029 etc.) or Hexadecimal (starts with 0x example: 0x10, 0x30 etc.)
floating constant- with precision values. example: 5.20,8.50, 0.5E-5 where E-5 means 10^-5 etc.  


Character Constant 

Single Character Constant- always used inside single quotes. example: 'A', 'a' etc.
String Constant/ Literal String-always used inside double quotes. example: "abc", "Hello" etc.

Escape Sequence

Escape Sequence are the character combination having special meaning on output without typed display. The list of Escape sequence with their meaning given below:

Escape Sequence Character Escape Sequence Character
\b Backspace \n NewLine
\f Form Feed \r return
\t Horizontal Tab \v vertical Tab
\' Single Quotation Mark \" Double Quotation Mark
\? Question Mark \0 Null Character
\\ Backslash

Variable

Variables are the naming words for storing the value in memory. Example: int count=10; where count is a variable of integer type and assigning integer constant 10.

Rules for Naming the Variable in C Language-

1. It should not be reserve word (Keyword like int, float etc are not allowed).

2. White Space is not allowed in Variable naming.

3. Only alphabets(a-z,A-Z), digits(0-9) and only underscore( _ ) special symbol is allowed.

4. Variable name should be of 31 character long and previous limit was 8 characters long.

5. Variable not allowed to start with digits.

6. Special symbols are not allowed except underscore( _ ).

7. Two variables of same name with same letter case(small or capital) in same scope(in curly braces {}) is not allowed.


Examples Status Example Status
count correct count_ correct
_count correct @count incorrect, it violates rule 6
max_count correct max count incorrect, it violates rule 2
count20 correct 20count incorrect, it violates rule 5
INT correct but not good practice int incorrect, it violates rule 1

Special Symbols/ Characters


Special Symbols or Characters used in C Language
+ - * / % &
! @ # $ ^ (
) _ \ ~ < >
? : ; " ' .
{ } [ ] |

No comments:

Post a Comment