Coupon Accepted Successfully!


Comma in Place of Curly Braces

The curly braces ({}) are used to define the body of function and scope of the control statements. The opening curly brace ({) indicates starting of the scope and closing curly (}) brace indicates the end of the scope. It is also possible to use comma operator in condition and loop statement in place of {} to indicate the scope of the statement. The use of comma operator is not allowed in definition of function. The following declaration is invalid.


The following program explains the use of comma operator with conditional and loop statements.

4.33 Write a program to use comma operator in if–else structure as scope indicator.


Explanation: In the above program, integer variable x is declared and initialized with 10. The if statement checks the value of x and executes respective blocks. The statements of if and else blocks are terminated by comma. The last statements of if block and else block are terminated by a semicolon to indicate the end of scopes. In this program, the if block is executed.

4.34 Write a program to use comma operator in for loop to indicate the scope.

Explanation: In the above program, the statements terminated by comma are included in the scope of for loop. The first two statements are terminated by comma and the last statement is terminated by semicolon, that is end of scope of for loop.

Test Your Skills Now!
Take a Quiz now
Reviewer Name