Programming Basics-2
Ashish Ranjan Mishra
Assistant Professor
Rajkiya Engineering College Sonbhadra
Fundamental Data Types in C
• used for declaring variables or functions of
different types.
• Space occupied in memory
• Bit Pattern is stored is interpreted
• Following are Fundamental Data Types in C
– Integer data type
– Floating point Data type
– Character Data type
– Boolean Data type
Integer Data Types
• Integer Data Type
– Used to declare integer variables or function
– integer types with their storage sizes and value
ranges: int a, int main()
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
int
short 2 bytes -32,768 to 32,767
unsigned 2 bytes 0 to 65,535
short
long 8 bytes or (4bytes -9223372036854775808 to 9223372036854775807
for 32 bit OS)
unsigned 8 bytes 0 to 18446744073709551615
long
Character Data Types
• Character Data Types
– Used to declare Character Variables or functions
– character types with their storage sizes and value
ranges: Char a=‘a’, char fun()
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
Floating Point Data Types
• Floating Point Data Types
– Used to declare Float Variables or functions
– floating types with their storage sizes and value
ranges: float a, float fun()
float 4 byte -3.4E38 to 3.4E38 6 decimal places
double 8 byte -1.7E308 to 1.7E308 15 decimal places
long double 10 byte 1.7E4932 to 1.7E4932 19 decimal places
Boolean Data Type
• Boolean Data Type
– Used to declare the Boolean variables or function
– It occupies only 1 bit in the memory.
– Store either 0 or 1.
• bool a, bool fun()
Storage Classes in C
• Storage class is used to fully defined a variable
• Storage class defines
– Stored Memory Location (Register, Main Memory)
– Initial Value of Variables (if not specified then
garbage value)
– Scope of variable (Global Scope or local scope)
– Life time of the variable (How long Variable
Available in memory)
Types of Storage Classes
• Automatic storage class
• Register storage class
• Static storage class
• External storage class
Automatic Storage class
• The variable defined as an automatic storage
class has following features
Storage Main Memory
Default Initial Value Unpredictable Value (Garbage)
Scope Local to block in which the
variable is defined
Life time Till the control remains within
the block in which variable is
defined
• See the following program how automatic
storage class is declared and executed
Automatic Storage class
Register Storage Class
• The variable defined as a register storage class
has following features
Storage CPU Register
Default Initial Value Unpredictable Value (Garbage)
Scope Local to block in which the
variable is defined
Life time Till the control remains within
the block in which variable is
defined
• See the following program how register storage
class is declared and executed
Register Storage Class
Static Storage Class
• The variable defined as a static storage class
has following features
Storage Main memory
Default Initial Value Zero
Scope Local to block in which the
variable is defined
Life time Value of the variable persist
between different function call
• See the following program how static storage
class is declared and executed
Static Storage Class
External Storage Class
• The variable defined as an external storage class
has following features
Storage Main memory
Default Initial Value Zero
Scope Global
Life time As long as the program’s
execution doesn’t come to an end
• See the following program how external storage
class is declared and executed
External Storage Class