Node:Assigning variables to one another, Next:, Previous:Characters, Up:Bits and pieces



Assigning variables to one another

Not only can you assign numbers to variables, you can assign other variables to variables:

var1 = 23;
var2 = var1;

The variable or value on either side of the = symbol must usually be of the same type. However, integers 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