Introduction to C
Data Types in C
Operators in C
Hello World Program
Loops in C
Single Dimensional Array
Two Dimesnional Arrays
Array Example Programs
Here, we are going to discuss data types in 'C' programming language. To discuss about the various data types in
'C', first it is necessary to understand what exactly are data types.
Data Type:- It can be defined as an extensive system for declaring variables of different types. These are used to store various types of data that is processed by program. It determines memory to be allocated to a variable.
'C' supports various data types such as integer, character, float, real, double etc. Data types are of two types namely primitive and non-primitive data type.
1. Primary or primitive data types
These are the predefined data types whose memory sizes are already fixed. For example: integer, character, float etc.
2. Secondary or Non-primitive Data Types
These are the user defined data types and its memory size depends on user. For example:- Array, Structure etc. We will discuss these data types in later chapters.
Size and Range of Data Types
Here we will see the various primary data types in 'C' with their size(number of bytes required to allocate a variable) and its range.
Actually, its no need to remember the range of these data types. You wonder how they came.
Lets see how the range came for the various data types. You only need to remember the bytes required for each data
Suppose, we take the example of integer. As, we see that the bytes required for a character is 2 bytes. And, we know that 1 byte = 8 bits. So, 2 bytes = 8x2 = 16 bits. Raise it in the power of 2.
So, (2)16 = 2 to the power of 16 = 65536.
But, integer can be positive and negative both. So, divide the result by 2 i.e, 65536/2 = 32768.
Hence, its range will be -32768 to 32767.
It is noted here that there will be a zero between the range that's why the maximum is 32767.
Similarly, range for any data type can be find out. Hope, now its easier for you to calculate and no need to remember it further...