What are the variables?
We must imagine the variables as the drawers of our bedside table, where we can put the things we want to save temporarily.
There are various types of variables, those mainly used are integer variables “int” where integer numbers are saved, “char” character variables where all the characters are saved (from the alphabet to particular characters like @ #., …… ….) And variables of real numbers “float” where the real numbers are saved with the decimal part.
How are the variables declared?
The variable name must be written in lowercase and can take any name. It is always better to give names that indicate what those variables are.
Now let’s try to give values to these keyboard variables.
To give values, use the “scanf ()” function.
If we want to save an integer number we have to write “scanf (“%d”, &number); “
%d indicates that we must save an integer, &number (where number and the name of our variable) indicates that the whole number that we input from the keyboard will save it in our variable.
Instead, to save a character, use “%c” and to save a decimal number “%f”.
Also to display the variables on the screen then you have to tell the printf what type of variable it should print and its name.
Example printf (“%d”, number);
By entering ” // ” the line will turn green and is a comment line where you can write on that line all the time the compiler will skip it.
As you can see from the photo in the printf I inserted the “ \n “ tab that indicates to go to the next line to view.