C language supports wide varieties of data types to accommodate any types of data manipulation the variety of data types available allow the programmer to select the type appropriate to the - needs for the program as well as the machine. Mainly the C language supports two types of data. type such as:
1. Primary data types (or the fundamental data types).
2. Secondary data types.
Again the secondary data type is divided into two types one is Derived data type and another one is User-defined data type. The total graphical representation of data types is given in the Fig.
Integers are whole numbers. Some, examples of variables that can have values only in whole numbers are numbers of gun shots, numbers of events, and number of objects such as cars and trucks. The type code for such variables is int. Integers are also differentiated into the following three categories according to their size:
(i) For variables having small integer values, the type code is short int or short.
(ii) For variables having intermediate range of values, the type code is int.
(iii) For variables having large integer values, the type code is long int or long.
(iv) For variables having very large values, the type is long long int or,simply long long.
Integers may be positive numbers or negative numbers. Therefore, out of the allocated memory space for integers, the leftmost bit is reserved for sign of the number. If this bit is 0, the number is positive, and if it is 1, the number is negative. This, however, decreases the size of memory and hence the maximum value that can be stored in the allocated memory to half because we are losing the most significant bit.
short int or short: Generally, in a 32-bit computer system, 2 bytes (16 bits) are allocated for storage of short int. Out of the 16 bits, the leftmost bit is reserved for sign, therefore, only 15 bits are available for the storage of the value. The values of short int variables may, therefore, vary from -32768 to 32767. As mentioned above, for the positive numbers, the leftmost bit is O; for negative numbers the leftmost bit is 1, and the remaining bits store complement of the number plus 1.
The variables of type int are allocated 4 bytes (32 bits) of memory space. As discussed earlier, the leftmost bit is reserved for sign, and the value of number is stored in the remaining 31 bits. Therefore, the range of values that these variables may have varies from - (2^{31}) to ( 2^{31}-1), that is, from -2147483648 to 2147483647.
On most of 32-bit systems, a long int is also allocated only 4 bytes. In that case, the range of values is same as for int. However, on some systems they may be allocated 8 bytes and the long long int gets 8 bytes or more for its storage. The ranges of values for different integer variables are listed in Table.
Memory and range of values for integer types
Integer types |
Memory allocated |
Range of values from minimum to maximum |
signed char |
1 byte |
-128 to+ 127 |
short int |
2 bytes |
-32768 to + 32767 |
int |
4 bytes |
-2147483648 to+ 2147483647 |
long int |
4 bytes |
-2147483648 to+ 2147483647 |
long long int |
8 bytes |
-9223372036854775808 to+ 9223372036854775807 |
Positive integers have many applications. An example is the number of runs made by players in a cricket match. Another example is the number of houses in a colony. In case of computer memory, RAM is segmented into bytes, and each byte is numbered sequentially. A number in this sequence is the address of the byte. Obviously, this number has to be positive. Such numbers are called unsigned numbers. The signed numbers can be positive or negative, but unsigned numbers are always positive. Unsigned numbers are also categorized according to their size, as shown in Table. For storing an unsigned number, we can use the entire allocated memory space because no bit is required for representing sign of a number. Therefore, the maximum value of unsigned number that may be stored in a given memory space is double that of signed numbers.
Range of values of unsigned numbers
Type |
Memory allocated |
Maximum value |
Range of values |
unsigned char |
1 byte |
2^{8}- 1 |
0 to 255 |
unsigned short int |
2 bytes |
2^{16}- 1 |
0 to 65535 |
unsigned int |
4 bytes |
2^{32}- 1 |
o to 4294967295 |
unsigned long int |
4 bytes |
2^{32}- 1 |
0 to 4294967295 |
unsigned long long int |
8 bytes |
2^{64}- 1 |
0 to 18446744073709551615 |
The term floating point has originated from the method in which the number is stored in computer memory. Consider that the number 52.5 is to be stored. In binary number system, it is written as 110100.1. The number is stored as .1101001 x 2^{6}. On a 32-bit system, the number 1101001 is stored on the 23-bit segment of the 32 bits, while the power 6 or 110 in binary is floated, that is, it is stored separately on the 8-bit segment of the remaining 9 bits. The leftmost bit (32nd bit) is kept for sign (+ or -). For positive numbers, this bit takes the value 0, and for negative numbers, this bit has value 1. The scientific notation for floating point numbers is the exponential notation. The number 7685.43 may be written as 7.68543 x 10^{3}. In C language, the scientific notation of the number 7685.43 may be expressed as 7.68543 e+3 or 7.68543 E+3.
The data types for floating point numbers are float, double, and long double. The distinction between float and double is according to the precision, that is, the number of digits after the decimal point. On most 32-bit systems, a float has 7 significant digits and is allocated 4 bytes of memory, whereas a double has 15 significant digits, nearly double the precision of float. It may get 8, 10, 12, or 16 bytes for storage on some systems. The memory spaces generally allocated for a float, double, and long double are given in Table.
Memory allocated for floating point numbers
Type |
Memory allocated |
Range of values that may be stored |
float |
4 |
± (3.4 e-38 to 3.4 e+38) |
double |
8 |
± (1.7 e-308 to 1.7 e+308) |
long double |
10 |
± (3.4 e-4932 to 1.1 e+4932 |
A variable may have value in the form of a character. The type of such variables is char. In C language, the characters are defined as integer constants according to ASCII code. This code comprises Latin alphabets from A to Z in uppercase and a to z in lowercase, digits 0 to 9, symbols such as+, - , *, etc. According to this code, each character is equivalent to a constant numerical value. The characters have values in the range from 0 to 127. In the list, value of each character differs from that of the previous by 1. The first 32 characters and the last character are the control characters and cannot be printed; the other characters may be printed. Therefore, for storing the value of a variable whose value is a character value, only 1 byte is required, and hence it is allocated 1 byte by the compiler.
In C language, the character set comprises the following groups of characters:
26 uppercase Latin alphabets
AB CDEFG HIJKLMNO PQR S TUVWXY Z
26 lowercase Latin alphabets
ab c def g h ij k 1m no p qr st u v w x y z
10 digits
0123456789
29 graphic characters
!"#%&'()*+,-./:;<=>?[\]/\_{I}~
7 control characters or non-printing characters
The control characters are space character, control characters representing horizontal tab, vertical tab, and form feed characters, etc. A byte in which all bits are set to 0 represents the null character.
The ASCII code supports only Latin alphabets and other symbols that have values from 0 to 127 and thus can be stored in 1byte of memory. Other languages are not represented by ASCII code. For representing alphabets of major languages of world, International Organization for Standardization (ISO) has created a Universal Character Set (UCS) code. It is designated as ISO 10464 standard. In this code, a character is allocated 4 bytes for storing its value. This is known as UCS-4. Before this standard was adopted, the Unicode (also called UCS-2) that allocated 2 bytes for a character was prevalent. The Unicode standard has also been modified to 4 bytes in accordance with ISO standard. The new ISO standard supports all the three, that is, ASCII, UCS-2, and UCS-4. The revised C standard supports ISO standard.
Illustrates the numerical equivalence of characters.
#include<stdio.h>
main ()
{
int x;
char ch = 65;
char kh = 66;
clrscr();
x = 'Z';
printf("The character ch %c\n",ch);
printf("The character kh %c\n",kh);
printf("x = %d\n",x);
}
The expected output is as given below.
Explanation of the output: The character ',A; is equivalent to numerical value 65 in decimal number system (with base 10). The character 'B' is equivalent to 66. The numerical value of 'Z' as per ASCII code is 90.
Boolean Type
Yet another new type added to C is the Boolean type integer, which is coded as _Bool. However, in C++ it is coded as bool. When a logical statement is analyzed, it is found to be either true or false. We may associate a number say 1 if the statement is true and 0 if it is false. For example, a program may contain the following condition:
_Bool x ;
x = (A> B);
Now, if this condition is actually true (say, if A= 7 and B= 6), value 1will be assigned to x. And, if the expression is false, then value 0 will be assigned to x. The above two statements could also be written as below.
_Bool x = (A> B);
Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.
Related Articles
Basic Courses
Advance Courses