Data Types In C
Introduction
Type of data play very important role in Programming.
For Example:
You might have filled Interactive forms on web like,
Enter Your Name : Sachin
Enter Your Salary : 45000.00
Enter Your Age : 30
Enter Gender : M
Enter Your Phone Number : 9922970696
and so on....
In this example . . . "Sachin" is String (Sequence of Characters/Array of Characters)
45000.00 is Real Constant, 30 is Decimal Constant, M is Single Character Constant, 9922970696 is decimal Constant.
Now, to use this kind of data in programs we must have to specify Type of Data before its use. This we can do with use of Data Types in C.
Data Types In C
The question here is when to use Data Types. . . ?
Data Types can be used while declaring Variables, Functions and so on.
Variables create memory space required to store data of specific type, for example if you create integer type variable like,
int num;
num will get occupy with 4 Bytes of memory, now these 4 bytes can be used to store integer data.
Similarly..
float variable require 4 bytes, char Variable require 1 byte, double Variable require 8 bytes and so on.
Data Types can be Categorize in following way
Categories of Data Types in C
Fig a. Data Types in C
Data Types can be categorized as shown in above figure.
Whenever we declare variable of any type, one thing that we should remember is, all data types have certain range of values. we cant assign out of range value to variables.
following table list out range of various data types in c. Table below also describes format specifiers used and size of variables in bytes.
Fig b. Range of Various Data Types in C
for Example:
1.
Let's declare one short int variable like. .
short int num;
As shown in above table, short int values ranges from -32768 to 32767, that means we can assign "num" variable with values within this range. we can't assign value outside range as
num=32769;
As 32769 is out of range of short int, it may give error or can store garbage value.
2.
Let's declare character variable
Default Declaration of character variable is signed character.
so. . . if you declare character variable like,
char ch;
now ch can hold values between -127 to 128. we cant assign any other value out of this range to variable ch.
Similarly variables of any type should be assigned with values within their prescribed range.
As per requirement user should decide which data type should be used.
for example
If you want to assign Mobile Number to variable, then declaring short int variable is not enough.
As short int range cannot hold 10 digits mobile number, user should declare signed int (default integer Data Type) like. . .
int Mobile_Number=8459765956
.
.
.
Thanks and Regards
Prof. Shivling G. Swami.
Head of Computer Science and Engineering,
Sant Gajanan Maharaj College of Engineering, Mahagaon.
Whats app and Contact Number : 99 22 970 696
This is very easy way to learn data type....Really Nice explanation sir👍 keep it up
ReplyDeleteThank you...
DeleteThank you...
DeleteBecause of this our short doubts cleared and this nice explanation.
ReplyDeleteThe way of explaining each term is awesome.....easy to understand concept 👍👍
ReplyDeleteNice explanation sir as always👏👍
ReplyDeleteGood Sir
ReplyDeleteThank you sir. .
DeleteIt is very easy to understand sir,
DeleteThank you sir..
Tq sir👋
ReplyDelete