C tokens
Individual words and punctuation in the passage of text are referred to as 'tokens'. In a C program, there are a number of individual units similarity, the smallest individual unit in a cprogram known as C tokens.C has six types of tokens:
1. Keywords
Keywords are words that have already been defined by a computer-they are predefined words in the C compiler. Each keyword is to perform a specific function in a C program, the keywords are case sensitive and are written in small case, and there are 32 keywords in the C language. Such as auto, int, long, long int, enum, return, case, char, do, if, goto, sizeof, while, struct, short, float, etc.
2. Identifiers
Identifier refers to variables, functions, and arena names, and these are user-defined names and have a sequence of letters and numbers with the letter as the first letter. They can contain both uppercase and lowercase letters.
Rules of identifiers
1. First character must be alphabets
2. Must consits of letters, digits and underscore
3. Only first 31 characters significant
4. Can not used keywords
5. Must not contain white space
3. Constants
C refers to fixed values that do not change their value during the execution of the program. There are two types of constant 1) numeric constant 2) character constant.
1. Numeric constant/integer constant
An integer constant refer to a sequence of digits. These are three types of integers.
1) Decimal
123
-321
0
654321
+78
2) Octal
An octal integer constants consist of any combination of digit from the set ‘0’ through ‘7’, with a leading ‘0’.
037
0
0435
0551
3) Hexadecimal
A sequence of digits preceded by ‘ox’ or ‘OX’ is considered as hexadecimal integer.
OX2
Ox9F
OXbcd
ox
2. character constant/String constants
A string constant is a sequence of characters enclosed in double quotes.
“Hello”
4. Strings
A string is a set of letters enclosed in double quotes.
For Example char string[]=”Name”
5. Special Characters
All letters except A to z, A to Z, and 0 to 9 are called special letters. For example, {,}, [,], (,) A character uses 8-bits of memory, which means that anyone can store anything in a character whose ASCII value is between -127 and 127. It can capture any of the 256 different potential values.
6. Operators
An operator a symbol than tells computer to perform certain logical or mathematic operation. Operators are use in program and variable and classify in to several categories. That provide 8 types of operators.
1. Arithmetic operators
C provide all the basic arithmetic operators. The all arithmetic operators have than significant to perform some kind of fre-predefined operators which are related to arithmetic operators.
Following are arithmetic operators in c.
Operator |
Meaning |
+ |
Addition or Unary plus |
- |
Subtraction or Unary minus |
* |
Multiplication |
/ |
Division |
% |
Modulo division |
2. Relational operators
Relational expression are used in dicision statements such as ‘if ‘and ‘while’ to deside the course of running program.
Operator |
Meaning |
< |
Is less than |
<= |
Is less than or equal to |
> |
Is greater than |
>= |
Is greater than or equal to |
== |
Is equal to |
!= |
Is not equal to |
3. Logical operators
An expression of this kinf which combines two or more relational expressions is termed as a logical expression or a compound relational expression.
operator |
Meaning |
&& |
And |
|| |
Or |
! |
Not |
4. Assignment operators
Assignment operators are used to assign the result of an expression to a variable. C has set off ‘shorthannd’ assignment operators of the form.
Syntax:
variable op=exp;
For example
X+=(y-2)
5. Increment & Decrement operators
operator |
Example |
Meaning |
++ |
A++ |
A=A+1 |
-- |
B-- |
B=B-1 |
The operator ++ adds 1 to the operand while – subtracs 1. Both are unary operators increment & decrement operators are unary operator.
6. Conditional operators/Ternary operators
Syatax
Exp1? Exp2: Exp3; |
Here exp1 is evaluated first. If it is nonzero, then the expression exp2 is evaluated and becomes the value of the expression. If exp1 is false, exp2 is true and exp3 is true.
For example:
a=(a<b)?a:b;
Conditional operators is used when the flow of exiqution defferance open some condition to be true or false.
7. Bitwise operators
operator |
Meaning |
& |
Bitwise and |
| |
Bitwise or |
^ |
Bitwise exclusive or |
<< |
Shift left |
>> |
Shift right |
~ |
One’s complement |
8. Special operators
1. The comma operator
2. The sizeof operator
3. Pointer operator
4. & and * operator
5. Member selection operator
0 Comments