Coupon Accepted Successfully!


Comma Operator

In C, every statement of the program is terminated by semicolon (;). In C++ it is applicable and in addition C++ allows us to terminate a statement using comma operator after satisfying the following rules.

  1. The variable declaration statements should be terminated by semicolon.
  2. The statements followed by declaration statements like clrscr(), cin, and cout can be terminated by comma operator.
  3. C++ permits declaration of variables at any point in program, but such declaration is not allowed in between the statements terminated by comma operator. The initialization of previously declared variables can be done.
  4. The last statement of the program must be terminated by semicolon.

Consider the following programs.

4.31 Write a program to use comma operator in place of semi-colon.


Explanation: In function main(), the first two statements are terminated by comma operator and the last statement is terminated by semicolon.

All the above points are noticed in the Turbo C++ compiler. The reader is advised to follow his/her own observations.

4.32 Write a program to declare an integer, initialize it and display it. Terminate the statements using comma operator.


Explanation: In the above program, the first and last statements are terminated by semicolon. Comma operator terminates the statements in between these two statements.

Test Your Skills Now!
Take a Quiz now
Reviewer Name