Data types in C

In this topic, we will learn about data types in c. Actually, what are data types? how many data types are there? let's dive into the topic.


int a=10;
As you see above example "a" is of an int data type. every variable in a program is of some data type. as per the above example "a" is of int data type and it can store only integer data. if you gave float value to integer data type, the compiler implicitly converts float to an integer type of value. if the character type of data is given to integer data type, the compiler raises an error indicating "char type cannot be assigned to integer".

Following are the common data types used in any language-

char: it is a basic data type. when you declare a variable of character type compiler allocates only 1 byte of memory to that variable and its range is 0 to 255 look at the following example-
char a="c";

int: when a variable declared as integer data type compiler allocates2 bytes of memory and it can store integer type of data only and its range is -2,147,483,648 to 2,147,483,6 look at the following example
int a=10;
Float-when a variable declared as float data type(meaning when a variable stores decimal value) compiler allocates 4 bytes of memory and it can store only float type of data.look at the following example.
float a=10.023;

memory is not allocated the same for both 32 and 64-bit compiler but they differ.following are the frequently used data types and the above-mentioned data types are primary data types which are basic data types.

Derived data types-this are data types which are derived from primary data types.for example, if variables are grouped together then such type of data type is called as array. arrays are the collection of variables.instead of writing 10 variables we write an array which is capable of storing 10 variables

int a[10];
you can read more about arrays from here

Post a comment

0 Comments