Datatypes and Variable in C

Let's See what are Datatypes and Variables In C.


Variables:
Before going to datatypes, first understand what a variable is.
Variable is name of the memory location where it is stored. In a computer, memory is stored in different location and the memory have their addresses. They are like “5048245” or “1054254” and something in the numeric manner. Variable is a user defined name to that location.
Keep in mind that every variable in C has a specific type. For example, if you want to store a name of the user, you have to store it in char(character) datatype. If you want to store a numeric data, which don’t have specific decimal point, go for int(integer).
For now, keep in mind, every C variable has a type.
main()
int marks;
Here, ‘int’ is the datatype, and ‘marks’ is a variable. All the data we store in marks will store in the location which marks points in memory.
Got some what idea for a variable? Lets now see Datatype.
Datatype:
Every variable carries data with a type which is datatype (didn’t it sound funny? Leave.)
Here are different datatypes with there requirements and memory size comsumption.
NameUseSize(in bytes)Specifiers
intfor a numeric elements like ’42’2%d
charfor a specific character like “&”1%c
floatfor number with decimal point like “1.250”4%f
doublefor number upto 10 element(like a phone number)8%lf
So, lets see the example so that, you can get cleared with it:
#include<stdio.h>
#include<conio.h>
main()
{
int marks;
printf(“Enter your Marks : “);
scanf(“%d”,&marks);
getch();
}
Output:
Enter Your Marks : 56
Here, ’56’ will be stored in the variable named “marks”, which would be for example ‘102151’ address in memory.
That was all you need to know about Datatype and its Variable.
If you have any query, ask me down.

Related Posts with Datatypes and Variable in C