You always assign whatever result from
right
side of '=' to the left side of '='.
x = x + 1;
1. Get the number from the box x.
2. Increase that number by 1.
3. Put the result back to the box x.
(The original number is erased).
If variable names
are different, you have different boxes to store it.
For example,
NumberOfStudents = 25;
cout << NumberOfStudent;
Will it print 25
out? No! since the names are not exact same.
Examples:
int A=4, B=3, C=5; // Initialize A to 4, B to 3, and C to 5.Think!!!!
C = A + B;The CPU pulls out the numbers from boxes A and B and adds them together.
4+3=7. Put the result, 7, back to C box. So, the original 5 in box C will be erased.
int A=4, B=3, C=7;
A + B = C; //Syntax error for this statement.You can have only one box in the left of '=' for an assignment statement.
int A=5, B=10;How about the following statements?
B=A;
cout<<setw(3)<<"A"<<setw(3)<<"B"<<endl;
cout<<setw(3)<<A<<setw(3)<<B<<endl;
int A=5, B=10;
A=B;
cout<<setw(3)<<"A"<<setw(3)<<"B"<<endl;
cout<<setw(3)<<A<<setw(3)<<B<<endl;