Professional Documents
Culture Documents
5 6314563731506332410
5 6314563731506332410
Computer
Processor
Input Processing Output
Figure 1: Basic operation of a computer
Control Unit
Input Output
Arithmetic-Logic Unit
Device Device
Memory Unit
7 1 0
Address
00FC
printf("\nDDDDD");
Figure 6: Tokens in C
Tokens
Keywords
Reserved words
Special meaning to compiler
Specific, predefined task for each keyword
Can not be used anywhere else for any other task
int a=123;
dataType variableName=value;
int a=123;
1002 1003 Address
0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 Content
a Name given to address
Variable Declaration
variableName
First letter can not be a number
• 1a, 5variables
• a1, variables5
No special character is allowed [Only underscore (_), dollar sign ($) allowed]
• @cse, ball#er, ball-er
• _cse, ball_er
• $cse, ball$er
No space is allowed within a variable name
• variables 5, ball er
• variables_5
No keyword can be used
• auto, union
• Auto, Union
Variable Declaration
Same variableName can not be used multiple times in a program
int a1;
int variables5;
char a1;
variableName(s) of same type can be declared in a single line or in separate lines
int a1, variables5;
---------------------
int a1=123, variables5=231;
----------------------------------
int a1=variables5=231;
Data Types in C
char (character)
Letters, single character
‘a’, ‘b’, …
int (integer)
Whole numbers
No decimal point
123, 321
float (floating point)
Numbers with decimal place
123.2541, 321.15976, …
double (double precision floating point)
Floating point numbers with more significant figures
123.254185637104
Data Types in C
char (character) 1002
8 bits 0 0 0 0 0 0 0 0
1 Byte
int (integer)
1002 1003
16 bits 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2 Bytes
float (floating point)
32 bits
4 Bytes
double (double precision floating point)
64 bits
8 Bytes
Range
char example=‘G’;
Data Types in C
ASCII (American Standard Code for Information Interchange)
Character code
char example=‘G’;
1002 Address
S 1 0 0 0 1 1 1 Content
example Name given to address
Data Types in C
int (integer)
1st bit as the sign bit
Rest of the 15 bits to store data
1002 1003
S 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Range
Data Types in C
float (floating point)
1st bit as the sign bit
Rest of the 31 (8 (exponent)+23 (mantissa)) bits to store data
6 decimal places (123.253614)
(Normalizing)
127+3=130 (Adding integer bias)
(Conversion)
0 10000010 10110100000000000000000 (Sign Exponent Mantissa)
00000000 00000000 01011010 1000001 (Reverse)
1002
S 0 0 0 0 0 0 0
1002
0 0 0 0 0 0 0 0
Data Types in C
int
signed int a; // same functionality as int
unsigned int a;
short int a; // same functionality as int
long int a; // 4 bytes so
unsigned short int a;
unsigned long int a; // 4 bytes without sign bit so
All of these could have been written without writing int. So both of the following are same
signed int a;
signed a;
1002 1003
S 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1002 1003
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Data Types in C
float
No modifier for float
double
long double a; // 10 bytes or 12 bytes
printf()
To display output on the screen