Simple Comma Operators Example Program In C++
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
C++ Operator Example Programs
- Simple Arithmetic Operators Example Program In C++
- Simple Relational Operator Example Program In C++
- Simple Logical Operators Example Program In C++
- Simple Assignment Operators Example Program In C++
- Simple Unary Operators Example Program In C++
- Simple Conditional or Ternary Operators Example Program In C++
- Simple Comma Operators Example Program In C++
- Simple Scope Resolution Operator Example Program In C++
- Simple new Memory Allocation Operator Example Program In C++
- Simple delete Memory Releasing Operator Example Program In C++
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Example Program For Copy Constructor In C++
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Example Program For Constructor Overloading In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Do While Loop Example Program In C++
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Exception Handling Divide by zero Using C++ Programming