Data types are the type of data stored in a C program. Data types are used while defining a variable or functions in C. The compiler needs to understand the type of predefined data it will encounter in the program.
In this article, you will get to know What is Data Types And illustration of each type.
Table of Contents
How this question can come in examination 2024?
- Explain various data types supported by C programming language giving suitable examples.
- What are data types in computer science? What are the data types supported by C language? Illustrate the importance of each.
- What are the different types of data types used in C- language? Explain with the help of an example.
Q1:- What are data types? What are the data types supported by C language? Illustrate the importance of each.
Data types are the type of data stored in a C- program. Data types are used while defining a variable or function in c. Data types are used while defining a variable or functions in C. The compiler needs to understand the type of predefined data it will encounter in the program. A data type is an attribute that tells a computer how to interpret the value.
C provides various built-in data types, such as integer(int), character(char), and floating point(float). Each data type has its own sets of possible values and operations that can be performed on it. C language becomes powerful with the help of some data types linked with it. Different compilers have different data types. The variable type depends on the data type.
There are mainly Five [5] types of data types supported by the C- language.
- Primary or scalar data type.
- Secondary or derived data type.
- User-defined or enumerated data type.
- Empty or void data type.
- Pointer data type.
1. Primary Or Scalar Data Type
A primary or scalar data type is used for representing a single value only. It is also called simple or fundamental data type. As these are used at the primary level in a high-level language, these are also called primary data types.
These are further sub-divided into four categories:-
A) Integer Data Type.
B) Float Data Type.
C) Double Data Type.
D) Character Data Type.
Integer Data Type:-
This data type is of integral type. These are without the decimal point. These are signed or unsigned. These data types contain small int (short int), int, long int. A short int is also called a small whole number. Int or normal integers are also called medium whole numbers and long ints are called long whole numbers.
Example:-
void main()
{
int i = 5;
printf(“The integer value is: %d \n”, i);
}
Integer data types have 8 bits to 32-bit data and also have different ranges for inputting the data or assigning data to the variable.
Float Data Type:-
This data type contains a very small real number. These data types have at least one digit with a decimal point. These are also signed or unsigned. These data types require storage space of 32 bits and have a range of 3.4E(-38) to 3.4E(+38) for inputting the data.
Example:-
void main()
{
float f = 7.2357;
printf(“The float value is: %f \n”, f);
}
Double Data Type:-
These data types have very large floating data, so are also called large real numbers. These have double precision values having the 64-bit size and a very high range of 3.4E(-4932) to 3.4E(+4932).
void main()
{
double d = 71.2357455;
printf(“The double value is: %lf \n”, d);
}
Character Data Type:-
These have either a single character or a combination of characters(called string). Characters are either signed or unsigned but most characters are used as unsigned type. These have 8 bits (1 byte) internal storage.
void main()
{
char c = ‘b’;
printf(“The character value is: %c \n”, c);
}
2. Secondary or Derived Data Type.
Derived data types are derived from the scalar data type by adding some additional relationship with various elements of primary or scalar data types. The derived data type may be used for representing a single value or multiple values.
These are further subdivided into 3 types:-
a). Arrays or strings.
b). Structures.
c). Unions.
3. Enumerated Or User Defined Data Type.
These data types are used for type definition i.e. allows the users to define a variable or an identifier, which is used for the representation of existing data types. In other words, it provides us a way to define our data type and also can define the value of a variable or an identifier stored in the main memory.
These are two types of user-defined data type:-
a) enumerated data type.
b) Typedef data type
4. Void Or empty Data Type.
The void is just an empty data type that depicts that no value is available. Typically, the void is used for functions. When we declare a function as void, it doesn’t have to return anything.
Void is used in three situations:
The function returns as void – A function with no return value will have the return type as void.
Function arguments as void – A function with no parameter can accept the void.
Pointers to void – It represents the address of an object, but not its type.
5. Pointer Data Type
The pointer data type is used to store the address of another variable. A pointer can store the address of variables of any data type. Pointers allow users to perform dynamic memory allocation. They also help to pass variables by reference.
A pointer with no address is called a null pointer. A pointer with no data type is a void Pointer. It is defined by using a ‘*’ operator.