0% found this document useful (0 votes)
8 views

1.4 C-Tokens, Data Types (Size and Range), Type Conversion

C-Tokens, Data Types(size and range), Type Conversion

Uploaded by

mlavidhayak802
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

1.4 C-Tokens, Data Types (Size and Range), Type Conversion

C-Tokens, Data Types(size and range), Type Conversion

Uploaded by

mlavidhayak802
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

C- Tokens

Manish Tiwari, Department of Computer Science & Engineering


Manish Tiwari, Department of Computer Science & Engineering
Character Set of C-Language
Alphabets A-Z and a-z
Digits 0-9
Special Symbols ~ ! @ # $ % ^ & ( ) _ - + = | \ { } [ ] : ; “ ‘< > , . ? /
White Spaces space , Horizontal tab, New Line etc..

Keywords:

Manish Tiwari, Department of Computer Science & Engineering


C-Tokens
 The smallest individual units of a C- program are called Tokens.
 Keywords, Identifiers, Constants, Operators, Delimiters.

Keywords :
 Have a predefined meaning and these meanings cannot be changed.
 All keywords must be written in small letters.
Identifiers :
 names of variables, functions, structures, unions, macros, labels, arrays etc.,
Rules for define identifiers :
a) First character must be alphabetic character or under score
b) Second character onwards alphabetic character of digit or under score.
c) First 63 characters of an identifier are significant.
d) Cannot duplicate a key word.
e) May not have a space or any other special symbol except under score.
f) C – language is Case-sensitive.

Manish Tiwari, Department of Computer Science & Engineering


C-Tokens
Constants :
 fixed values that do not change during execution of a program.

Operators :
a symbol, which indicates an operation to be performed. Operators are
used to manipulate data in program.

Delimiters :
Language Pattern of C-language uses special kind of symbols
: colon, used for labels
; semicolon terminates statement
() parameter list
[] array declaration and subscript
{} block statement
# hash for preprocessor directive
, comma variable separator

Manish Tiwari, Department of Computer Science & Engineering


Data Types In C

Manish Tiwari, Department of Computer Science & Engineering


(Basic)

int: signed, short, long, and unsigned


(Qualifiers)

 The type void either explicitly declares a function as returning no


value or creates generic pointers.

Manish Tiwari, Department of Computer Science & Engineering


Data Types in C

Data Type Format


Specifier
char %c

unsigned char %c

unsigned int %u

int %d

short int %d

long int %ld

Float %f

Double %lf

Long double %Lf


Manish Tiwari, Department of Computer Science & Engineering
Data Types in C
Data Type Size Range Format
Specifier

char 1 -128 to +127


%c
unsigned char 1 0 to 255

2 0 to 65535
unsigned int %u
4 0 to 4,294,967,295
2 -32768 to +32767
signed int %d
4 -2,147,483,648 to +2,147,483,647
1 -128 to +127
short int %d
2 -32768 to +32767
long int 4 -2,147,483,648 to +2,147,483,647 %ld
long long 8 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 %lld

float 4 1.7e -38 to 3.4e +38 %f


double 8 2.2e -308 to 1.7 e +308 %lf
Long double 10/16 3.4e -4932 to 3.4e +4932 %Lf

n bit unsigned range n bit signed range


0 to 2n -1 (- 2n-1) to (2n-1 -1)

Manish Tiwari, Department of Computer Science & Engineering


Manish Tiwari, Department of Computer Science & Engineering
Data Types in C

Manish Tiwari, Department of Computer Science & Engineering


#include<limits.h>

INT_MAX
INT_MIN
UINT_MAX
SHRT_MIN
SHRT_MAX
USHRT_MAX

LONG_MAX
LONG_MIN
ULONG_MAX

FLT_MAX
FLT_MIN
DBL_MAX
DBL_MIN

Manish Tiwari, Department of Computer Science & Engineering


size of float: 4
size of double: 8
size of long double: 16

FLT_MAX: 3.402823e+038
FLT_MIN: 1.175494e-038

DBL_MAX: 1.797693e+308
DBL_MIN: 2.225074e-308

lDBL_MAX: 3.205284e-317
LDBL_MIN: 3.205284e-317

Precision value of float: 6


Precision value of double: 15
Precision value of long double: 18

Manish Tiwari, Department of Computer Science & Engineering


Type Conversion
Converting one type into another.
Implicit type conversion
(automatic)
Explicit type conversion
While evaluating a+x first x will be
int x=10; converted into float, then addition
float a=10.5, b; will be done.
b= a + x; x will automatically be converted
into float. This is called implicit
conversion.

Manish Tiwari, Department of Computer Science & Engineering


Implicit Type Conversion
float x=10.10; While evaluating x*a ,
double a=10.5, first x will be converted into double,
float y=x *a; then addition will be done.
Long
Important: double
If the operators are of different types- Hierarchy
the lower type is automatically converted double
into higher type before the operation float
proceeds Long int
int

Note:
The final result of an expression is Final result will be float
convereted to the type of variable on LHS since y is float
of assignment operator.

Manish Tiwari, Department of Computer Science & Engineering


Explicit Type Conversion
Done by programmer:

float x=10.34,y=45.89; int a=20,b=6;


float x;
int a;
a=(int)x + (int)y ; x=(float)a / (float)b;

Here x and y are forcefully converted into int.


This is called Explicit Type Conversion.

Manish Tiwari, Department of Computer Science & Engineering


Mix-mod operation
 int/int=int int%int=int remainder
 int+int=int
 int-int=int int int = int
 int*int=int
flaot int =float
int float =float
float float=float

 float /int=float
 int/ float =float
 float/float=float

Manish Tiwari, Department of Computer Science & Engineering

You might also like