Do they yield the same result or different?

Do they yield the same result or different?

1.
1
2
  bool tf; int n;
  if(1) tf = true, n=2; //plz explain this.. tf=true, 


2.
1
2
3
bool tf; int n;
  if(1) {tf = true; n=2;}

Last edited on
They are the same, but you should prefer the second.

You may want to look up the boolean datatype.
How can a comma(,) be used after tf=true
The comma operator is a special operator in C++ that evaluates all arguments in order and returns the last.

http://ideone.com/Dl5Djs

In general it is a bad idea to use it.
Topic archived. No new replies allowed.