What is difference between val=3 and val==3.

Q5. Given the two following expressions:

a.val = 3

b. val==3


  1. How are these two different?
  2. What will be the result of the two if the value of val is 5 initially?

Ans.(1). The expressions (a.) is an assignment expression and the expression (b.) is a relational expression that tests for equality.

Ans.(2). The result of (a.) will be val having value 3 that is, 3  and the result of (b.) will be 0 (false) because 5 is not equal to 3.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: