Data Types in C language
The type of data that can be kept in a variable in a programming language is called data type. There are many types of data types such as integer, character, string, real, etc. which are kept in a variable in any programming language. All these types are known as data types.
In normal terms, when we declare a variable during programming, then you have to tell the compiler what type of data you want to store in the variable, the compiler provides the same amount of memory from the computer memory. With the ability to divide data into different types of language, you can easily work with complex programs. There are two reasons to know the difference between different types of data,
which is as follows -
- The compiler, which translates the program into object code (as 0 and 1), can use the appropriate internal representation for each data type.
- While designing a program, programmers can use the right operator to operate on data of every type.
BASIC DATA TYPES
C Language supports the following data types.
There is any programming language like - c, c ++, java, PHP, etc. Some data types are important for programming. Whenever we create a program, we need some memory to run that program on the computer. And we can take this memory only with the help of data type, the data type itself tells which type of value it is. We have come to know in an earlier post what the variable is and how to declare it. Declaring the variable only provides memory for the program and requires a data type to declare these variables.
Fundamental Data type -: Primary data type is also called Fundamental data type. They are of the following types.
- int
- char
- float
- string
All the "C" compilers support the five major primary data types named int, char, float, double, and string.
Integer
Integer types are used to store any whole number (a number without a decimal). There are 5 types of Integer types. However, they all store complete numbers. But they are divided based on memory size and range.
Example : long int population = 200000000;
Floating point
The floating-point data type is defined to store numbers with decimals. Floating-point data types are of 2 types. They are divided based on size and range. In float type, you can store up to 7 digits after the decimal. Whereas up to 17 digits after decimal can be stored in double type.
Example : double balance=810.12354984;
Character Type
Character Type is used to store a character. They are divided into 2 categories.
Example: char best language = “C”;
Void type
The void type is used in situations when you have no idea about the value. It is mostly used with functions. You can use Void type in C in these situations.
- If your function does not return any value, you define its return type Void. For example, you can define a function like this. void myFunction ();.
- If you are not taking any parameters in the function, then you can define Void there. Void type shows that no argument is taken in this function. For example, you can pass Void as a parameter in this way. int myFunction (void);.
- If you are not sure which type of variable will point to the variable then you can declare its type Void. After this, you can point to any variable with a Void pointer.