Summary: Outlines the three primary uses of the sequence operator within C++.
Note: You are viewing an old version of this document. The latest version is available here.
The sequence (or comma) operator is used to separate items. It has three primary uses:
int pig, dog, cat, rat;
This is often seen in textbooks, but this method of declaring variables is not preferred. It is difficult to quickly read the identifier names.
int pig;
int dog;
int cat;
int rat;
This vertical method of declaring variables or constants is preferred.
double area_trapezoid(double base, double height, double top);
The data types and identifier names (known as parameters) are separated from each other.
for( x = 1, y = 5; x < 15; x++, y--)
In the syntax of a for loop you have three parts each separated by a semi-colon. The first is the initialization area which could have more than one initialization. The last is the update area which could have more than one update.