What is Data Type and variables in C? Easy explanation with real world analogy.
PDF Link Click Here for PDF
PPT Link Click Here for PPT
Code Link Click Here For Code
What is Data Type?
The data type is an entity that specifies, what type of data we are storing in a variable.
There are mainly 2 type of data types in C:
- Primitive
- Non-primitive
- Enumeration (optional)
Let's understand them one by one.
Primitive Data Type
It is the system's pre-defined or pre-declared data structure and can store only one type of value.
Example: Integer, Float, Character.
Non-primitive Data Type
It is the user-defined data structure, which means we are the ones who will choose what and how to store our data in what manner.
Example: Array, Linked list, Stack, Queue, structure, pointer, union, etc.
Enumeration Data Type (optional)
It is also a user-defined data type, but it is reserved for making integral constants in the C language.
What is a Variable?
A Variable is like a container that stores a specific type of data.
You can understand easily by this example:
Have you ever seen a water bottle, it is the same as a variable. It is used to store water in it. The same thing happens with a variable in C, it is used to store the specified data type in it.
Syntax: data_type variable_name;
What is sizeof() function in C?
As understood by its name it is a C function, it gives the size of entity ( variables, datatype) whichever is passed in it.
Syntax: sizeof( entity );
If you want to know more you can refer to the below link, in which I have covered this part in the data structure in great detail. Click Here