Learning C-Style C++by Direct Approach Mentoring =3. Assignment=sign to store a value in a variable.For example, let's store the number 5in the variblen:5;No matter what nwas before, it is now5. The old value ofnis gone forever.Here are some more assignments for the varibles we created earlier: charletter;boolb;floatf;'A';true;1.555;You can also use assignment to set the starting value of a variable. Let's create a number called numberand start it at100:intnumber =100;Assignment works between variables, too. But here is the key point: Assignment only changes the value of the variable on the left side. Nothing on the right side is ever affected by assignment. The above line takes the value of numberand puts it inn.This means numberitself is not changed.Always: the computer looks to the right side of the =sign for a value. Then it stores this value the variable on the left side.Which means you must always have a variable on the left side to store into.
Next: 4. Operators
|