In addition, there are qualifiers which can be applied.
short and long may be applied to integers (when the int can be omitted entirely e.g. long int i is the same as long i.)
short, int and long may give different lengths, but not necessarily. The exact length depends on the implementation. However int is usually the natural size for the machine and they are guaranteed not to give counter-intuitive results (i.e. long cannot be shorter than int etc!).
signed and unsigned may be applied to char or any integer (it is not defined whether or not char by itself is signed)
long double specifies extended precision floating point. As with integers, float, double and long double may or may not be different sizes: you can only be sure that the smallest-named is no longer than the longest-named.
When any variable is declared, the const qualifier may be prepended to indicate that its value may not be updated. For an array, this means that the components may not be changed and this may also be used when an array is an argument to a function. The result of trying to change any const is implementation dependent.
Example
main()
{
int count;
count= 2; printf("Count is %d\n",count);
count= 8; printf("Count is %d\n",count);
}
This should print
Count is 2 Count is 8
on successive lines, showing that the value of count has changed.
Note also how we print the value of a variable: we use a ``conversion specification'' %d to say that the integer is to be output in decimal form (i.e. as a conventional integer) and we name the variable in a list after the comma.
The minimal form of this is
printf("%d",count);
and if we had several integer variables to print we might have used
printf("%d %d %d \n",variable1,variable2,variable3);
There is a corresponding routine to read in a value to a variable (or a list of variables):
scanf("%d",&count);
Note the use of the address-of operator (&) so that scanf knows where to store the value.
We will return to this in more detail in a chapter on input/output.
maspjw@