• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

= Operator

 
Thillakan Saba
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please any one explain following code segment ?

 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are two copies of the same code......

well the if(flag = true) has a gotcha....there is = and not ==. So it is an assignment not comparison. This will make the condition true.

flag = false;
if(flag = true)//it will result in flag becoming true and condition becoming true too..
 
Thillakan Saba
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oopps!! Thanks,
boolean values can be used with in if block with = operator.
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in java = is different of the == in the exam there are serveral questions so.
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sabanayakam Thillakan:
Oopps!! Thanks,
boolean values can be used with in if block with = operator.


This is a similar problem as = with ints in C and C++.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic