Expanding a little furhter on the answer....
{} is used for two purpose one is to initialise multi dimesinal array and another place is to define the body of the function
{} are used not just to define the body of a function, but more generically to execute a block of statements. Most commonly this is if you want a conditional statement or loop to execute more than one statement, you put these parentheses around all the code you want executed in that condition.
eg:
-
if(something)
-
{
-
printf("somethind is true");
-
doSomethingElse();
-
}
-
Without the parentheses, the program would execute the printf if something is true and the doSomethingElse method irrespective of the value of something. (I'm starting to think something is a bad variable name)
( ) is used while calculation similar to mathematics....some times it may used in the specify the subset of the array but that is not a common
() is used to explicitly show order of computation. This is for logical and computational values. () are also required to define parameter lists for functions (and must still be included is there are no parameters), and are required as part of the syntax of some statements.
It is always better to include too many rather than too few of these (assuming they're in the right place, because their placement can affect the result of an expression). Consider what the boolean logic below does and when it returns true
-
boolean this, that, what
-
if(this && that || what == true) i
-
-
//is this the same
-
if((this && that) || what)
-
/* Requires that either both this AND that are true OR at least what is true */
-
-
// or maybe
-
if((this && (that || what))
-
/* require that this is true AND either that or what is true*/
-
-