+ 1
is it necessary to put the curly Braces { } after the if() and else? Coz in the code below i didnt put braces and it worked well
#include <iostream> using namespace std; int main() { int x=1; if(x>0) cout<<"positive number"<<endl; else cout<<"negative number"; return 0; }
4 Respostas
+ 2
You only need to use brackets if it's more than one line. You only used one line in this case, so it works.
+ 1
Curly brackets are only required if you want to put more than only one instruction in the block...
+ 1
it is not necessary if you have only one instruction after the If or Else. if there is more than one instruction, you need braces
+ 1
Thank you All