Simple Comma Operators Example Program In C++
On this page (7sections)
About this program
This is an example program in c operator example programs. Read the concept first: Arithmetic Operators Example in C++, then study the code and output below.
The Comma Operator
- The Comma operator can be used to link the related expressions together.
Example For Comma Operator
Comma Operator In for Loops
for(i=0,j=1;i>10:i++,j++)
Comma Operator In while Loops
While(c<10,c--)
Comma Operator Example Program
// Header Files
#include<iostream>
#include<conio.h>
#include<stdio.h>
//Main Function
using namespace std;
int main ()
{
// Variable Declaration
int a = 10, b= 5,i,j; // comma usage in declaration
cout << "Simple Comma Operators Example Program In C++\n";
/* Comma Operators link the related expressions together*/
a = (a++,b++);
cout<<"\nComma Operators Usage : "<<a; //Pre Increment
/* Comma Operator In for Loops*/
for(i=0,j=1;i<a;i++,i++)
{
cout<<"\nComma Operator : for Loop : "<<i<<" : "<<j; //Pre Increment
}
cout<<"\n\nComma Operators for execute two functions : ";
(printf("\nFirst\n"),printf("Second\n")); // (func1(),func2())
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
Sample Output
Simple Comma Operators Example Program In C++
Comma Operators Usage : 5
Comma Operator : for Loop : 0 : 1
Comma Operator : for Loop : 2 : 1
Comma Operator : for Loop : 4 : 1
Comma Operators for execute two functions :
First
Second
Related Pages
Learn the concept first, then study the code:
- C++ Programs — Browse all C++ Programs.
- Arithmetic Operators Example in C++ — Tutorial — arithmetic, relational and logical operators.
- Simple Relational Operator Example Program In C++ — More in c operator example programs.
- Simple Logical Operators Example Program In C++ — More in c operator example programs.