Hello friends, today we are going to see the 'C' language primary data types and their qualifiers. See my 'C' constants, variables, and keywords post for further information.
Data types:
A data type is a set of data with values having predefined characteristics. Examples of data types are integer, float, characters, strings, and pointers, etc. Here we will discuss the primary data types and their Qualifiers.
Qualifiers:
A variation of the data type that will extend the accuracy of a variable. Examples of qualifiers are long, short, unsigned char, and double, etc. There are as follows.
Type int
An integer constant is any number in the range -32768 to +32767. It always occupies two bytes in memory. Out of two bytes, the highest bit (sixteenth bit) is used to store the sign of the integer. If this bit is 1, the number is negative. And if 0, the number is positive. Integer declaration is as follows.
Example: int integer_var;
integer_var = 100;
int integer_var = 100; etc.
Long:
long integer requires twice the space in memory and that’s why long integers would occupy four bytes of memory. Long integers are declared using the keyword long. The value of a long integer can vary from -2147483648 to +2147483647.
Example: long int I;
long int abc;
long height; etc.
Short:
A short int is our ordinary int, C allows the abbreviation of short int to int and long int to long. It requires less space in memory i.e. 2 bytes and that’s why it helps to speed up the program to execute.
Example: short int j;
Short int height;
Or simply int height;
Integers signed and unsigned:
Sometimes, the value stored in a given integer variable will always be positive like counting the things. In such case, declare the variable to be unsigned. The range of permissible integer values is 0 to 65535. It occupies 2-bytes memory space. The sixteenth bit is now free and is not used to store the sign of the number. Declarations are as follows.
Example: Short unsigned int i;
unsigned int i;
unsigned i;
By default, a short int is a signed short int and long int is a signed long int.
Type chars signed and unsigned:
A char variable can be used to store a single character such as a single alphabet or letter ’a’ the single-digit ’6’ or a single special symbol enclosed within single inverted commas. There are also signed and unsigned chars and both are occupying one byte in memory space, but having different ranges. A signed char or just our ordinary char having a range from -128 to + 127; whereas an unsigned char having a range from 0 to 255. The declaration is as follows.
Example: unsigned char ch;
Char char_var = ’w’;
Type floats and doubles:
A variable declared to be of type float can be used for storing values containing decimal places. It occupies four bytes in memory and can range from -3.4e38 to +3.4e38. If this range is insufficient then a double data type can be used which occupies 8 bytes in memory and has a range from -1.7e308 to +1.7e308. A long double occupies 10 bytes in memory and has a range from -1.7e4932 to +1.7e4932.
Example: float x;
double y, population;
long double z;
Charts display data types and their essential points.
Data Types
|
Range
|
Byte
|
Format
|
Signed char
|
-128 to +127
|
1
|
%c
|
Unsigned char
|
0 to 255
|
1
|
%c
|
Short signed int
|
-32768 to +32767
|
2
|
%d
|
Short unsigned int
|
0 to 65535
|
2
|
%u
|
Long signed int
|
-2147483648 to +2147483647
|
4
|
%1d
|
Long unsigned int
|
0 to 4294967295
|
4
|
%1u
|
Float
|
-3.4e38 to +3.4e38
|
4
|
%f
|
Double
|
-1.7e308 to +1.7e308
|
8
|
%1f
|
Long double
|
-1.7e4932 to 1.7e4932
|
10
|
%Lf
|
Well, friends, did you like my post please don't forget to leave comments on the comment box and share as much as possible.
Comments
Post a Comment
Your comment will inspire me, Please leave your comment