A variable is a small piece of your memory where you can store informations which are needed for your program.
Example:
#include <stdio.h>
When you run the program, you should see that screen:
void main()
{
int Number;
Number=5;
printf("%d\n", Number);
}
5
_
int Number; |
Here is the declaration of the variable (Attention: case sensitive!!) |
Number=5; |
means "set Number to 5" |
...("%d\n", Number)... |
\n is known, %d is replaced with the number on the right side. |
int declares the variable to be an integer. Here are some types:
char | one byte, takes one character |
int | an integer |
float | a floating point number |
double | a more precicios floating point number |
A constant is used like a variable, except that it cannot changed at runtime.
There are two ways to define constants. Example 1:
#include <stdio.h>
Example 2:
void main()
{
const int YES=1;
printf("%d\n", YES);
}
#include <stdio.h>
The const-command is preferred.
#define YES 1
void main()
{
printf("%d\n", YES);
}
You can use algebraic commands as normal (like with a calculator) in definitions. (i.e.: Number=3*5;
)