SlideShare a Scribd company logo
Data Types in C
int i ; 
short int i ; 
default 
signed short int i ; 
i 
Type of Integers 
int 
short int long int 
signed short unsigned short 
Specifier: %u 
Specifier: %i %d 
%o %x %X 
15 bits = value 
max value 
111 1111 1111 1111 
32767 
Sign bit 
0 - Positive 
1 - Negative 
Range:-32768 to 
+32767 
Size: 2 Bytes 
Range: 0 to 
65535 
Size: 2 Bytes
Type of Integers 
Sign bit 
0 - Positive 
int 1 - Negative 
111 1111 1111 1111 1111 1111 1111 1111 
short int long int 
signed unsigned 
Specifier: %ld 
long int a 
31 bits = value 
max value 
2147483647 
long signed long unsigned 
Specifier: %lu 
Range: -2147483648 to 
+2147483647 
Size: 4 Bytes 
Range: 0 to 
4294967295 
Size: 4 Bytes
Type of Chars 
char 
char ch ; 
Sign bit 7 bits = value 
0 - Positive 
1 - Negative 
signed char unsigned char 
Specifier: %c Specifier: %c 
max value 
111 1111 
127 
Range : -128 to + 127 
Size : 1 Byte 
Range: 0 to 255 
Size: 1 Byte
Types of Real 
Real 
float double long double 
Range: -3.4*1038 to 
+3.4*1038 
Size: 4 bytes 
Specifier: %f 
Range: -1.7*10308 
to +1.7*10308 
Size: 8 bytes 
Specifier: %lf 
Range: -1.7*104932 
to +1.7*104932 
Size: 10 bytes 
Specifier: %Lf 
1 - 8 - 23 1 - 11 - 52 1 - 15 - 64 
127 1023 16383
int 
short int long int 
signed unsigned signed unsigned 
char Real 
signed unsigned float double long double
Chars With a Sign? 
char ch = ’A’ ; 
ch 
65 
char dh = -15 ; 
dh 
-15
What If We Exceed The 
Range? 
signed char ch = 128 ; 
printf ( ”%d”, ch ) ; 
-128 
Why?
Why This Bias? 
char 
-128 +127 
int 
-32768 +32767 
long int 
-2147483648 +2147483647
signed char ch 
= -128 ; 
Binary of 128 
10000000 
1’s complement 
01111111 
2’s complement 
10000000 
printf ( ”%d”, ch ) ; 
-128 
unsigned char dh 
= 128 ; 
signed char eh 
= 128 ; 
Binary of 128 
10000000 
printf ( ”%u”, dh ) ; 
Binary of 128 
10000000 
Add 0 for Positive 
Sign bit 
010000000 
Store rightmost 
8 bits 
10000000 
printf ( ”%d”, eh ) ; 
01111111 
+1 
10000000 
-128 
128
Various Forms 
signed short int i ; 
short signed int i ; 
short int i ; 
signed int i ; 
int i ; 
short i ; 
signed i ; 
unsigned short int j ; 
short unsigned int j ; 
unsigned int j ; 
unsigned j ; 
long signed int k ; 
signed long int k ; 
long int k ; 
long k ; 
long unsigned int i ; 
unsigned long int i ; 
unsigned long i ; 
signed char ch ; 
char signed ch ; 
char ch ; 
unsigned char dh ; 
float a ; 
long double e ; 
char unsigned dh ; 
double d ;
What Is 365? 
int 365 
long int 
unsigned int 
unsigned long int 
365L 365l 
365u 
365lu 365ul 
What Is 3.14? 
double 3.14 
float 
long double 
3.14f 
3.14L
Would This Work 
main( ) 
{ 
int i ; 
  
for ( i = 0 ; i = 255 ; i++ ) 
printf ( ”%d %c”, i, i ) ; 
} 
char i ; unsigned char i ;
Stick To Your Guns 
main( ) 
{ 
for ( i = 0 ; i  255 
; i++ ) 
printf ( ”%d %c”, i, i ) ; 
} 
unsigned char i ; 
printf ( ”%d %c”, i, i ) ;
Storage Classes In C 
A Complete definition of variable : 
Type 
Storage Class
A Storage Class signifies 
Storage 
Default Initial Value 
Scope 
Life
Types of Storage Classes 
Automatic 
Register 
Static 
External
Automatic Storage Class 
Storage 
Default Initial Value 
Scope 
Life 
Memory 
Garbage 
Local to the block in which 
the variable is defined 
Till the control is in the 
block in which the 
variable is defined
Automatic Storage Class 
main( ) 
{ 
int a ; 
static int b ; 
automatic int c ; 
printf ( ”%d %d %d”, a, b, c ) ; 
automatic 
auto 
} 
Error 
?
Default Initial Value 
main( ) 
{ 
int a ; 
static int b ; 
auto int c ; 
printf ( ”%d%d%d”, a, b, c ) ; 
} 
G 0 G
Which Is Correct? 
main( ) 
{ 
int a = 10 ; 
float a = 3.14 ; 
. . . . . . . 
. . . . . . . 
} 
main( ) 
{ 
int a = 10 ; 
int a = 20 ; 
. . . . . . . 
. . . . . . . 
 } 
 
TTiipp:: RReeddeeffiinniittiioonn nnoott aalllloowweedd
Redefinition? 
main( ) 
{ 
int a = 10 ; 
{ 
int a = 20 ; 
{ 
int a = 30 ; 
printf ( ”%d”, a ) ; 
} 
printf ( ”%d”, a ) ; 
} 
printf ( ”%d”, a ) ; 
} 
Error ! Why? 
main ( ) 
{ 
int a = 20 ; 
f ( ) ; 
}f 
( ) 
{ 
printf ( ”%d”, a ) ; 
} 
30 
20 
10
Death, But When? 
main( ) 
{ 
Won’t die when the 
control goes to f( ) 
int i =10, j = 20, k, l ; 
k = f ( ) ; 
l = i + j + k ; 
printf ( ”%d”, l ) ; 
} 
f ( ) 
{ 
int m = 5, n ; 
n = m * 2 ; 
return ( n ) ; 
} 
Would die when 
control goes back
Register Storage Class 
Storage : 
Default Initial value : 
Scope : 
Life : 
CPU Registers 14 Each of 2 bytes 
Central Processing 
Unit 
Microprocessor μp
Different Speeds? 
main( ) 
{ 
auto int i ; register int i ; 
for ( i = 1 ; i = 250 ; i++ ) 
printf ( ”%d %c”, i, i ) ; 
} 
main( ) 
{ 
for ( i = 1 ; i = 250 ; i++ ) 
printf ( ”%d %c”, i, i ) ; 
} 
Register Storage Class 
Storage : CPU Registers 
Default Initial Value : Garbage 
Scope : Local to the block in which the variable is defined 
Life : Till the control remains in the block in which 
the variable is defined
Be Judicious 
main( ) 
{ 
register int i ; register int j = 20 ; 
for ( i = 1 ; i = 250 ; i++ ) 
printf ( ”%d %c”, i, i ) ; 
printf ( ”%d”, j ) ; 
}

More Related Content

DOCX
Technical questions
PPTX
Safe int
PPT
Lecture03
PPSX
Programming in C [Module One]
PDF
PPTX
Huffman Coding Algorithm Presentation
DOC
C operators
PDF
C language questions_answers_explanation
Technical questions
Safe int
Lecture03
Programming in C [Module One]
Huffman Coding Algorithm Presentation
C operators
C language questions_answers_explanation

What's hot (20)

PPT
Mesics lecture 5 input – output in ‘c’
PDF
9 character string & string library
PDF
C Prog. - ASCII Values, Break, Continue
DOC
All VLSI programs
PPTX
Introduction to C programming
PPTX
Part - 3 Cpp programming Solved MCQ
PPTX
Expressions using operator in c
DOC
C lab-programs
PDF
Keygenning using the Z3 SMT Solver
PDF
9. pointer, pointer & function
PDF
2 data and c
PPTX
Decision making and branching
PPS
T02 a firstcprogram
PDF
C++17 not your father’s c++
PPTX
Input Output Management In C Programming
PDF
The solution manual of c by robin
PPT
Cbasic
PPT
Lecture 10 - Multi-Party Computation Protocols
PDF
Introduction to cpp
Mesics lecture 5 input – output in ‘c’
9 character string & string library
C Prog. - ASCII Values, Break, Continue
All VLSI programs
Introduction to C programming
Part - 3 Cpp programming Solved MCQ
Expressions using operator in c
C lab-programs
Keygenning using the Z3 SMT Solver
9. pointer, pointer & function
2 data and c
Decision making and branching
T02 a firstcprogram
C++17 not your father’s c++
Input Output Management In C Programming
The solution manual of c by robin
Cbasic
Lecture 10 - Multi-Party Computation Protocols
Introduction to cpp
Ad

Viewers also liked (17)

PPTX
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
PPT
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
PPTX
ELEMENTARY DATASTRUCTURES
PPT
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
PPTX
DOC
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
PPT
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
DOCX
DOCX
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
ELEMENTARY DATASTRUCTURES
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Ad

Similar to Vcs14 (20)

PPTX
C Programming Language
PDF
Fundamentals C programming and strong your skills.
PPT
C tutorial
PPT
Lập trình C
PDF
深入淺出C語言
PPT
Unit i intro-operators
PPS
T02 a firstcprogram
PPT
Interesting facts on c
PPTX
C++ lectures all chapters in one slide.pptx
PDF
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
DOCX
Qust & ans inc
PPT
C C++ tutorial for beginners- tibacademy.in
PPTX
1 introduction to c program
PPT
Unit1 C
PPT
Unit1 C
PPTX
Programming in C Basics
PPT
Lecture 3 c++
C Programming Language
Fundamentals C programming and strong your skills.
C tutorial
Lập trình C
深入淺出C語言
Unit i intro-operators
T02 a firstcprogram
Interesting facts on c
C++ lectures all chapters in one slide.pptx
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
Qust & ans inc
C C++ tutorial for beginners- tibacademy.in
1 introduction to c program
Unit1 C
Unit1 C
Programming in C Basics
Lecture 3 c++

More from Malikireddy Bramhananda Reddy (15)

PDF
M v bramhananda reddy dsa complete notes
PPT
B-TREE PREPARED BY M V BRAHMANANDA REDDY
PPT
DATASTRUCTURES UNIT-1
PPT
Data representation UNIT-1
PDF
C SLIDES PREPARED BY M V B REDDY
DOC
C AND DATASTRUCTURES PREPARED BY M V B REDDY

Vcs14

  • 2. int i ; short int i ; default signed short int i ; i Type of Integers int short int long int signed short unsigned short Specifier: %u Specifier: %i %d %o %x %X 15 bits = value max value 111 1111 1111 1111 32767 Sign bit 0 - Positive 1 - Negative Range:-32768 to +32767 Size: 2 Bytes Range: 0 to 65535 Size: 2 Bytes
  • 3. Type of Integers Sign bit 0 - Positive int 1 - Negative 111 1111 1111 1111 1111 1111 1111 1111 short int long int signed unsigned Specifier: %ld long int a 31 bits = value max value 2147483647 long signed long unsigned Specifier: %lu Range: -2147483648 to +2147483647 Size: 4 Bytes Range: 0 to 4294967295 Size: 4 Bytes
  • 4. Type of Chars char char ch ; Sign bit 7 bits = value 0 - Positive 1 - Negative signed char unsigned char Specifier: %c Specifier: %c max value 111 1111 127 Range : -128 to + 127 Size : 1 Byte Range: 0 to 255 Size: 1 Byte
  • 5. Types of Real Real float double long double Range: -3.4*1038 to +3.4*1038 Size: 4 bytes Specifier: %f Range: -1.7*10308 to +1.7*10308 Size: 8 bytes Specifier: %lf Range: -1.7*104932 to +1.7*104932 Size: 10 bytes Specifier: %Lf 1 - 8 - 23 1 - 11 - 52 1 - 15 - 64 127 1023 16383
  • 6. int short int long int signed unsigned signed unsigned char Real signed unsigned float double long double
  • 7. Chars With a Sign? char ch = ’A’ ; ch 65 char dh = -15 ; dh -15
  • 8. What If We Exceed The Range? signed char ch = 128 ; printf ( ”%d”, ch ) ; -128 Why?
  • 9. Why This Bias? char -128 +127 int -32768 +32767 long int -2147483648 +2147483647
  • 10. signed char ch = -128 ; Binary of 128 10000000 1’s complement 01111111 2’s complement 10000000 printf ( ”%d”, ch ) ; -128 unsigned char dh = 128 ; signed char eh = 128 ; Binary of 128 10000000 printf ( ”%u”, dh ) ; Binary of 128 10000000 Add 0 for Positive Sign bit 010000000 Store rightmost 8 bits 10000000 printf ( ”%d”, eh ) ; 01111111 +1 10000000 -128 128
  • 11. Various Forms signed short int i ; short signed int i ; short int i ; signed int i ; int i ; short i ; signed i ; unsigned short int j ; short unsigned int j ; unsigned int j ; unsigned j ; long signed int k ; signed long int k ; long int k ; long k ; long unsigned int i ; unsigned long int i ; unsigned long i ; signed char ch ; char signed ch ; char ch ; unsigned char dh ; float a ; long double e ; char unsigned dh ; double d ;
  • 12. What Is 365? int 365 long int unsigned int unsigned long int 365L 365l 365u 365lu 365ul What Is 3.14? double 3.14 float long double 3.14f 3.14L
  • 13. Would This Work main( ) { int i ; for ( i = 0 ; i = 255 ; i++ ) printf ( ”%d %c”, i, i ) ; } char i ; unsigned char i ;
  • 14. Stick To Your Guns main( ) { for ( i = 0 ; i 255 ; i++ ) printf ( ”%d %c”, i, i ) ; } unsigned char i ; printf ( ”%d %c”, i, i ) ;
  • 15. Storage Classes In C A Complete definition of variable : Type Storage Class
  • 16. A Storage Class signifies Storage Default Initial Value Scope Life
  • 17. Types of Storage Classes Automatic Register Static External
  • 18. Automatic Storage Class Storage Default Initial Value Scope Life Memory Garbage Local to the block in which the variable is defined Till the control is in the block in which the variable is defined
  • 19. Automatic Storage Class main( ) { int a ; static int b ; automatic int c ; printf ( ”%d %d %d”, a, b, c ) ; automatic auto } Error ?
  • 20. Default Initial Value main( ) { int a ; static int b ; auto int c ; printf ( ”%d%d%d”, a, b, c ) ; } G 0 G
  • 21. Which Is Correct? main( ) { int a = 10 ; float a = 3.14 ; . . . . . . . . . . . . . . } main( ) { int a = 10 ; int a = 20 ; . . . . . . . . . . . . . . } TTiipp:: RReeddeeffiinniittiioonn nnoott aalllloowweedd
  • 22. Redefinition? main( ) { int a = 10 ; { int a = 20 ; { int a = 30 ; printf ( ”%d”, a ) ; } printf ( ”%d”, a ) ; } printf ( ”%d”, a ) ; } Error ! Why? main ( ) { int a = 20 ; f ( ) ; }f ( ) { printf ( ”%d”, a ) ; } 30 20 10
  • 23. Death, But When? main( ) { Won’t die when the control goes to f( ) int i =10, j = 20, k, l ; k = f ( ) ; l = i + j + k ; printf ( ”%d”, l ) ; } f ( ) { int m = 5, n ; n = m * 2 ; return ( n ) ; } Would die when control goes back
  • 24. Register Storage Class Storage : Default Initial value : Scope : Life : CPU Registers 14 Each of 2 bytes Central Processing Unit Microprocessor μp
  • 25. Different Speeds? main( ) { auto int i ; register int i ; for ( i = 1 ; i = 250 ; i++ ) printf ( ”%d %c”, i, i ) ; } main( ) { for ( i = 1 ; i = 250 ; i++ ) printf ( ”%d %c”, i, i ) ; } Register Storage Class Storage : CPU Registers Default Initial Value : Garbage Scope : Local to the block in which the variable is defined Life : Till the control remains in the block in which the variable is defined
  • 26. Be Judicious main( ) { register int i ; register int j = 20 ; for ( i = 1 ; i = 250 ; i++ ) printf ( ”%d %c”, i, i ) ; printf ( ”%d”, j ) ; }