valid assignments

Given:
int num1,num2,newNum;
double x,y;
Which of the following assignments are valid?If an assignment is not valid,state the reason.When not given assume that each variable is declared.
a.num1=35
b.newNum=num1-num2;
c.num1=5;
d.num2=2+num1;
e.x=12*num1-15.3;
f.num1*2=newNum+num2;
g.x/y=x*y;
h.num2=num1%2.0;
i.newNum=static_cast<int>(x)%5;
j.x=x+y-5
k.newNum=num1+static_cast<int>(4.6/2);
In C++ all operations must occur to the right of the assignment operator. So letters:
f and g are not valid because the compiler does not know where to assign the result of the right side of the equation.

Also, assigning an integer a double value is possible, but anything beyond the decimal is going to get truncated.
Topic archived. No new replies allowed.