3.The float Data Type:
The float data type in c language is used to store all real numbers.
.The range of the real number it can store vries from compiler to compiler.Float data type in C may havee both, the exponential part as well as the decimal part (or the fraction part). It is basically a single-precision type of number.
for 32-bit and 64-bit compiler it is the same as 4 bytes.That is equivalent to 2^(4*8) length of value.
which is 4,29,49,67,296 i.e.0 to 4,29,49,67,296
4.The double data type
Basically The size of the double data type is 64 bits or 8 bytes. It is capable of storing values that are comparatively double the size of the bytes that the float data type can store. This is the reason why it is known as the double. When looking at the 64 bits in total, the program has 1 bit for the sake of sign representation, the exponent uses 11 bits, and it uses the remaining 52 bits for the mantissa.
This data type is capable of holding about 15-17 digits, both after and before the decimal of the data type.
5. Void Data type
Void data type in C language has no meaning and do not have any size.
It is also known as empty data type that is used to declare variable that do not have any type.
Most importantly it is used in defining functions where function do not return any value.
Every data type variable occupies some bytes of memory , it depends on the compiler either it is 32 bit or 64-bit compiler.
Following program demostrate Size of data type in C language
2. Derived Data Types
A derived data type in C language is basically an combination or aggregation of the primary data type. Examples of primary data types are Void, Float, Integer, and Character. Structures, Unions, Arrays, and Pointers are the derived data types. Derived data types are derived from the primary or fundamental data types.
1.Array:
An array is a collection of elements of the same data type. It used to handle a large amount of data, without the need to declare many individual variables separately. The array elements stored in contiguous memory locations (i.e. one after the other). All the array elements must either any primary data type like int, float, char, double etc., or they can be any user-defined data type like structure and unions.
To declare an array, you need to specify the type of the array elements and number of elements.
The syntax is
data_type arrayname[size];
2.Functions:
A function is a group of statements that together perform a task . It allows us to avoid duplicating code that used more than once in Program. Using functions the program, can divide into smaller piece of code parts that are easier for us and others to understand, modify and maintain the program.
Functions can divided into two categories: library functions (in-built functions) and user-defined functions.
Library functions are predefined and precompiled functions that designed to perform some specific tasks.
Example Built in Function is , printf (),scanf (), sqrt (), strlen (), pow() etc.
User-defined functions are the functions which are explicitly defined by the user to meet his requirements. A user-defined function generally created when a user may require to perform some specific task repeatedly, and there is no library function available for performing this task.
Every function in C consists of following components function definition (part of the function where actual code is defined), function prototype (specifies the name of the function, number and type of parameters (if any) and its return type), function call (It used to invoke the function by specifying the function name followed by a list of arguments separating the function name followed by a list of arguments separated by commas enclosed in pair of parentheses).
3.Pointer: Pointer
A pointer is a variable that contains the address of the data items such as variable or function or array rather than a value. It is a derived data type as it built from one of the basic types available in C.
Pointers frequently used in C because of pointer provides efficient techniques for manipulating data in arrays.
function in C programming always return value, to return multiple values from function pointer is used.
Pointers support run type of dynamic memory allocation.
A pointer variable can be declared in the same way as that of normal variable except that an asterisk must precede the name of the pointer variable (*).
The syntax is
data_type *ptr_var_name
For example
int *ptr;
Here, ptr is a pointer variable, Which stores the address of any another variable whose data type is int.
Once the pointer variable is declared, we can initialize the pointer variable by assigning the address of some other variable by using the address of operator (&).
For example :
int p = 15;
int *ptr = &p;
A pointer variable can also use to indirectly access the value of the variable whose address stored in it. It is using the dereference operator (*).
3. User Defined Data Types in C
As the name suggests, these data types are created by users using one or more primitive or basic data types in combination.These data types are defined or created by the user as per their need. If a user feels a need of having a data type which is not predefined in C library, then they make their own.
Primitive or basic data types Structure, union, enum type definitions help to define user-defined types.
Structure : Structure is a user-defined data type in C, where we can store values of multiple data types.
For example, if you want to store details of employees of a company, where each employee will be having a name, empno and salary. But managing the data of one employee together (string, int and float variable) for a employee is not possible with any of the data types we have discussed so far. Now for this we use another data type known as Structure.
Union: Union is Similar to Structure.
Unions consist of one or more members which may be of different data types just like structures. However, unlike structures where each member is assigned a unique storage area, in the union, all the members share the same storage area within the computer’s memory.
In union the space allocation is equal to the highest memory required by the data type.
The e.g is:
Enum:Enumerated Data Types
C provides a special kind of user-defined data type known as enumerated type.
Enum is user defined data type which is used to make program more redable and undersandable to prpgrammer.The main objective of enum is to assign text values to the concerned index value.
The programmer lists the values that a variable of enumerated data type can take.
Now let us consider a statement,
enum countries{America,India,China,Japan,England,Shrilanka};
in the above statement 0 will be assigned to America,1 India,2 china and so on.