Sunday, April 10, 2011

Datatypes in C and C++

The basic datatypes available in C and C++ are integers, floats, characters, and strings. Integers can be short or long. Short integers uses two bytes to store the number, whereas long integers use four bytes to stores integer values. Therefore the range of short integers is -32768 to +32767 and that of long integers -2147483647 to +2147483647

Character datatype can hold single characters like 'a' or 'b'. Character variables use one byte of storage.

Strings datatype is used to hold a set of characters together like name of a person "sam". It is necessary of use cotation marks on both sides of string to indicate that it is string.

Datatype float is used to hold floating point numbers or numbers with decimal points like 4.50 or 5.80. These decimal ponit numbers cannot be storeds into integer variables, and if we assign any floating point number to an integer then only integer part of the float number will get assigned to the variable. So it is necessary to use flaot variables to store floating point numbers.

No comments:

Post a Comment