Variables can be assigned to numbers:
var = 10;
and assigned to each other:
var1 = var2;
In either case the objects on either side of the = symbol must be of the same
type. It is possible (though not usually sensible) to assign a floating point
number to a character for instance. So
int a, b = 1;
a = b;
is a valid statement, and:
float x = 1.4;
char ch;
ch = x;
is a valid statement, since the truncated value 1 can be assigned to ch. This
is a questionable practice though. It is unclear why anyone would choose to
do this. Numerical values and characters will interconvert because characters
are stored by their ASCII codes (which are integers!) Thus the following will
work:
int i;
char ch = ’A’;
i = ch;
printf ("The ASCII code of %c is %d",ch,i);
The result of this would be:
The ASCII code of A is 65