The Assignment Operators
In C, the assignment operator is the equal sign = and is used to give a variable
the value of an expression.
For example:
- i=0;
- x=34.8;
- sum=a+b;
- midinit='J';
- j=j+3;
when assigning a character value the character should be enclosed in single
quotes.
In the assignment statement
a=7;
two things actually occur. The integer variable a gets the value of 7, and the
expression a=7 evaluates to 7. This allows a shorthand for multiple
assignments of the same value to several variables in a single statement. Such
as
x=y=z=13.0;
as opposed to
x=13.0;
y=13.0;
z=13.0;
The following example illustrates two methods for variable initialization:
which produces the following output:
No comments:
Post a Comment