Data Types:


Variables in a program occupy some space in computer’s memory where some value is stored. A value to be stored may be an integer, floating point number, a character or a string etc. But now the question arises that how much memory is allocated to these values and what is the range of values that can be stored in it as different types of values don’t occupy some space in memory. So to store these values, we require different data types depending on the needs of the application.
C supports different types of data which may be represented differently within computer’s memory.

The data types are divided into three classes:
  1.       Basic or Primary data type
  2.      Derived data type
  3.       User- defined data types

Primary Data Types:
int, char, float and double are basic data types available in C. They are argumented by using data by using data type qualifiers such as short, long, signed and unsigned. These are used to change the size or sign of data type.

Integer Type:
Integer type is used to store whole numbers without a fractional part. In C, the keyword int is used to represent integer quantity. They generally require 2 bytes of  memory for their storage. This is a signed data type i.e. it can be used to store both positive as well as negative values.
Range of values that variables of this type can hold lies between -32768 to 32767.
Declaration of a variable length of int type as follow:

   int length;


Character Type:
The char type is used to represent individual characters enclosed within single quotes. Therefore, the char type will generally require 1 byte of memory. Each char type has an equivalent integer interpretation. The char type data permit character that has ASCII values extending from -128 to +127. There is also unsigned char data which permit character that have ASCII values extending from 0 to 255. By default, character data type is treated as unsigned character. The conversion character used with this data type is %c normally.


Floating Point Types:

The integer types do not provide the facility to represent decimal numbers so whenever you represent a number with a decimal such as 3.142 use a floating- point data type. If you try to use an integer type to type to store a number with fractional part, the fractional part simply be discarded. C provides two standard floating- point types: float and double to store numbers with fractional parts. These give you a choice in the number of digits precision available to represent your values in the range of values that can be accommodated.

Previous                                                                                   Next

Powered by Blogger.