+ 3
Why dont we use cali-brackets {} in C++ when we using the if statemets
I have seen many programs & I have done some..if use {} it doesn't work
4 Answers
+ 6
We do! but some people prefer not to when there is only one instruction line following the if statement:
if(...)
// one line instruction
if(...)
{
// instruction
// more instruction
}
If there is more than one line of instruction following if statement wrap them in curly braces, one line? not necessary, but if we prefer to wrap the one line C++ has no problem with that.
Hth, cmiiw
+ 2
if it contains only one statement we need not use {} in the"if statement". Otherwise we must use {}. If we didn't use syntax error will occur.
0
ŠŠ“Šµ ŃŃŃŃŠŗŠøŠø?