Variables are used to store values during program run-time. The value stored inside a variable can change or vary and hence the name “Variable”. The variables occupy memory inside RAM (depending on the data type).
Data types specify the type of data that will be stored inside a variable. C language has some predefined data types each with its own usage.
In C, a variable is always declared with a data type which specifies what data will the variable store.
Consider the following code snippet.
int num1; //1 int num2 = 5; //2
In the first line, we declare a variable named “num1” which will only store integer type values.
In the second line, we declare another variable “num2” and assign a value of 5 to it. Remember that this value can always be changed later on anywhere in the program.
Here is a list of the most used data types:
|Size in bytes||Usage|
|char||‘1’||Stores a single keyboard character|
|bool||‘1’||Stores either ‘true’ or ‘false’ as ‘1’ or ‘0’ |
|int||‘2’||Stores integer values ranging from -32,768 to 32,767|
|long||‘4’||Stores integer values ranging from −2,147,483,647, +2,147,483,647|
|float||‘4’||Stores 32 bit decimal values|
|double||‘8’||Stores 64 bit decimal values|
In the upcoming tutorials, we will be putting these data types into practical use.