Wednesday, December 12, 2007

Data types , Variables and constants in C language

DATA TYPES

Data type means type of data. suppose if you are counting number of person in that case it will be
number, Name of a person is in Alphabets ,Address may be combination of numbers and alphabet and so on .

C too has data types to denote any type of data

for Alphabet(we will denote it as character from now on)

char------for the use of name,address etc

for Digits

int------for the use of numbers eg 1,3,67 etc(which do not have fractional part eg 1.2,23.34 etc)
float-----for the use of currency 12.2,1.00 etc.

At first we will just look at the examples of them

char-----'A' , 'a', 'abc'
in case of 'abc' it will only consider it as 'a' because char only permits single letter

int----1,2,3,45,678
you can clearly see that there is no decimal point "." involved it is not allowed,but if you include decimal it will consider digit before decimal eg 1.23 will yield in 1 and .23 will get truncated

float-----1.2,1.5,1.00
if you take a number suppose 1 ,then it will automatically add decimal point to it and make it 1.00

Type specifiers

long
short
signed
unsigned

if you look at the way the data is stored at memory,the first bit is for negative or positive sign
let us look at a example

long :- It is is used to increase the number range of of integers (it is compiler Dependant)
short :-
It is is used to decrease the number range of of integers (it is compiler Dependant)

signed :- It will take both negative and positive numbers
unsigned :- It will take only positive numbers


Variables
They are the place holders for any type of data means you can store any data in them according to data types.As it name suggest that its value can be changed as and when required by the user