+ 3
Is it necessary to write â{}â in if statement, if here is only two lines in it?
//Example if(x<y){ y=88 y=9} //or if(x<y) y=88 y=9
10 Respostas
+ 6
Have you tried the comma operator? It works in some cases, like the one you have here. Helpful when you want to save some braced lines.
Eg :
#include <iostream>
using namespace std;
int main()
{
int x=1, y=2;
if(x<y) y=88,y=9;
cout<<y;
}
+ 6
in 1st code
if( x<y ) {
y = 88;
y = 9;
}
if condition is true block of code executed
and
in 2nd code
if( x<y )
y = 88;
y = 9;
if condition is true y = 88 executed otherwise rest of flow execution ie y = 9 executed !
+ 3
@Kishuk Vasisht
Thanks a lot!
+ 2
Thatâs what I needed
+ 2
But how much I can write in one line?
+ 2
@Sofia S. Tkachenko
There isn't any limit to the use of the comma operator. It can be used simultaneously for 3, 4 or more lines. Its just that the operator fails when you use some type of functions like system(), exit(), etc..
+ 1
Yes, you must if you're having multiple lines of code.
+ 1
Thx
+ 1
Iâve already understood)
+ 1
But thx