0% found this document useful (0 votes)
17 views43 pages

01 Tokens

aboyt c prohrammingAC

Uploaded by

ankush02481
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views43 pages

01 Tokens

aboyt c prohrammingAC

Uploaded by

ankush02481
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Tokens

By: Dr. Prakash Singh


Tanwar
Tokens
Keywords

Identifier

Tokens Literals

String

Operator

By: Dr. Prakash Singh


Tanwar
Keywords
Reserved words

32 keywords in C

50 Keywords in java

Small case

By: Dr. Prakash Singh


Tanwar
Keywords
Conditional Unconditio- Storage Extra
Datatypes Datatypes Control nal Control Class
(13) (3)
(8) (4) (4)

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

By: Dr. Prakash Singh


Tanwar
Identifier Names
User defined names
Variable name

Array name

Function name

Etc.

By: Dr. Prakash Singh


Tanwar
Rules for Identifier names
1. Identifier names must start with
alphabets(A-Z,a-z), digits(0-9) and
underscore(_).
Empname 
Emp1 

emp_name 

By: Dr. Prakash Singh


Tanwar
Rules for Identifier names
2. Keywords are not allowed for
identifier name.
int X

Float 
float X

int_float 
By: Dr. Prakash Singh
Tanwar
Rules for Identifier names
3. First character of identifier name
must be an alphabet or
underscore(_)
1emp X
Emp_name 
_emp1 

By: Dr. Prakash Singh


Tanwar
Rules for Identifier names
4. White space characters(space,
tab, newline) are not allowed for
identifier name.
Emp name X

emp name X

By: Dr. Prakash Singh


Tanwar
Rules for Identifier names
5. Any other special character
except underscore(_) are not
allowed for identifier name.
Amount@100 X
Emp# X
Price_in_$ X

By: Dr. Prakash Singh


Tanwar
Rules for Identifier names
6. Uppercase and lowercase are
distinct in C for identifier name
(Case sensitive)
Name and name are two different identifiers

emP and EMP are two different identifiers

By: Dr. Prakash Singh


Tanwar
Rules for Identifier names
7. Length of Identifier name depends
on compiler
Some compiler allows maximum 10
character
• employee_name1 and employee_name2 are
identical(same)

Some can have 31 characters length

By: Dr. Prakash Singh


Tanwar
Literals
Value remains unchanged for
literals
Literals

Non
Numeric
Numeric

Integer Real Character

By: Dr. Prakash Singh


Tanwar
Literals
Integer Literals
Numbers without fractional part are
integer literals

Without Point

Ex.
• 54

• 234
By: Dr. Prakash Singh
Tanwar
Literals
Integer Literals
There are three type of integer Literals
i. Decimal

ii. Octal

iii. Hexadecimal

By: Dr. Prakash Singh


Tanwar
Literals
Integer Literals
i. Decimal Integer Literals
Digits (0 to 9)

Symbol (+ & -)

Alphabets (u, U, l, L)
• 123  0  +123  -123 
• 123456l  1,256 X 1 234 X $256 X

• 15ORs X 1245U 

By: Dr. Prakash Singh


Tanwar
Literals
Integer Literals

ii. Octal Integer Literals


We must write 0 (Zero) prefix before octal integer literals.
It is used to identify octal number.

Digits : 0 to 7

Symbol : + and –

Alphabets : u, U, l, L

By: Dr. Prakash Singh


Tanwar
Literals
Integer Literals

ii. Octal Integer Literals

0145  0583 X 05,673 X

$0583 X 05673  06 73 X

5_673 X

By: Dr. Prakash Singh


Tanwar
Literals
Integer Literals

iii. Hexa Decimal Integer Literals

We must write 0x or 0X prefix before


hexadecimal integer literals. This prefix
is used to identify hexadecimal integer
literals.

By: Dr. Prakash Singh


Tanwar
Literals
Integer Literals

iii. Hexa Decimal Integer Literals

Digits : 0 to 9

Alphabets : A to F , a to f , x, X

Symbol : + and –

U, u , l, L at and as suffix
By: Dr. Prakash Singh
Tanwar
Hexadecimal integer Literals
Integer Literals

iii. Hexa Decimal Integer Literals


0xab1  0Xabc  +0x547 

0x54 732 X 0x5,632 X 0x123 


0XABCL  0XABCU  0xABUL 

0xAUB X
By: Dr. Prakash Singh
Tanwar
Literals
Rules for Integer Literals
Digits, +, -, are allowed

White space characters are not allowed

Special characters except (+ or -) are


not allowed

By: Dr. Prakash Singh


Tanwar
Literals
Rules for Integer Literals
We must write 0 (zero) before octal
integer Literals
• 0123

We must write 0x or 0X before


hexadecimal integer literals
• 0x1A
By: Dr. Prakash Singh
Tanwar
Literals
Rules for Integer Literals
We should write l or L after long integer
literals
• 12345678l

• 12345678L

By: Dr. Prakash Singh


Tanwar
Literals
Rules for Integer Literals
We should write u or U after unsigned
integer Literals
• 12345u

• 12345U

By: Dr. Prakash Singh


Tanwar
Literals
Real Literals
Number with fractional part are called real
literals

Ex.
• 3.4  5.231  53.  .42 
• 0.32  1,234.4 X 1234Rs X
• $123.5 X 123 54.2 X 3.2X103 X

By: Dr. Prakash Singh


Tanwar
Literals
Real Literals
Ex. In C language 3.2X103 can be written as
3.2e3
• 3.2e3 
• 3.2e+3 
• 3.2e-3 
• 3.2E3 
• 3.2e2.4 X
By: Dr. Prakash Singh
Tanwar
Literals
Non Numeric Literals
Character Literals
• with in single quotes (‘ ’)

• Ex. ‘A’, ‘$’, ‘1’

By: Dr. Prakash Singh


Tanwar
Literals

Character Literals

Character
Literals
Single Backslash Trigraph
character character character
Literals Literals Literal

By: Dr. Prakash Singh


Tanwar
Non Numeric Literals
Single character Literals
Single character literals any character
with in single quote.

Ex :
• ‘A’ ‘a’ ‘@’ ‘1’

By: Dr. Prakash Singh


Tanwar
Non Numeric Literals
Backslash Character Literals /
Escape Sequences
‘\n’ :- New Line ‘\’’ :- ’

‘\t’ :-Tab ‘\”’ :- ”

‘\a’ :- Alarm ‘\b’ :- backspace

‘\\’ :- \

By: Dr. Prakash Singh


Tanwar
Non Numeric Literals
Trigraph Character Literals

(Rarely used)

‘???’ : ?

‘??’’ : ’

‘??”’ : “

By: Dr. Prakash Singh


Tanwar
Literals
String
Group of characters in double quotes (“ ”).

Ex Result
• “Hello PST”  Hello PST
• “Hello PST, How are you?” Hello PST, How are you?

• “Hello “PST” ” X Error


• “Hello \”PST\”” Hello “PST”

• “Hello \”PST”  Hello “PST
By: Dr. Prakash Singh
Tanwar
Literals
String
Ex Result
• “Hello ‘PST ” X Error
• “Hello \’PST\’”  Hello ‘PST’
• “Hello \’PST”  Hello ‘PST
• “Hello \”PST\’”  Hello “PST’
• “@#$%^&”  @#$%^&

By: Dr. Prakash Singh


Tanwar
Literals
String
Ex Result
• “old\new”  old

ew
• “old\\new”  old\new
• “mango\banana”  manganana
• “mango\\banana”  mango\banana

By: Dr. Prakash Singh


Tanwar
Exercise
Determine which of the following
are identifiers. if invalid, explain
why?

record1  $tax X name-and---address X


1record X name
 123-45-6789 X
name and address X
file_3

return X name_and_address

By: Dr. Prakash Singh


Tanwar
Thank You

By

Dr. Prakash Singh Tanwar

By: Dr. Prakash Singh


Tanwar
Exercise

Distinct
Distinct
Identical
Distinct
Distinct
Distinct

By: Dr. Prakash Singh


Tanwar
Exercise

 

X 

 X

 X

By: Dr. Prakash Singh


Tanwar
Exercise


X


X

By: Dr. Prakash Singh


Tanwar
Exercise

  
 X

 

By: Dr. Prakash Singh


Tanwar
Exercise

By: Dr. Prakash Singh


Tanwar
Exercise


By: Dr. Prakash Singh


Tanwar

You might also like