Simple Explanation

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
int main()
{
  int v1=7, v2=5, v3=0;
  v3=v1 * (v2=6);
  cout << v3 << endl;
  return 0;
}



What does v3=v1 * (v2=6) mean?

Thank you!
6 is assigned to v2 and the product of v1 and v2 is assigned to v3.
int v1 = 7 is saying v1 holds the value 7
int v2 = 5 is saying v2 holds the value 5
int v3 = 0 is saying v3 holds the value 0
v3 = v1 * (v2 = 6); is saying v3 = the value of : v1 * 6, v1 currently holds the value 7, so v3 = 7 * 6 which is 42.
cout << v3 << endl; will display 42.
Topic archived. No new replies allowed.