|
From: Vassili <v.v...@bt...> - 2001-08-27 13:04:47
|
Here is a snip from the wrox press tutorial, it might help explain a few =
things:
Try It Out - The Comma Operator
The comma operator allows you to specify several expressions where =
normally only one might occur. This is best understood by looking at an =
example of how it is used:
// EX1_05.CPP
// Exercising the comma operator
#include <iostream>
using namespace std;
int main()
{
long num1 =3D 0, num2 =3D 0, num3 =3D 0, num4 =3D 0;
num4 =3D (num1 =3D 10, num2 =3D 20, num3 =3D 30);
cout << endl
<< "The value of a series of expressions "
<< "is the value of the right most: "
<< num4;
cout << endl;
return 0;
}
How It Works
If you compile and run this program you will get this output:
The value of a series of expressions is the value of the right most: 30
This is fairly self-explanatory. The variable num4 receives the value of =
the last of the series of three assignments, the value of an assignment =
being the value assigned to the left-hand side. The parentheses in the =
assignment for num4 are essential. You could try executing this without =
them to see the effect. Without the parentheses, the first expression =
separated by commas in the series will become:
num4 =3D num1 =3D 10
So, num4 will have the value 10.
Of course, the expressions separated by the comma operator don't have to =
be assignments. We could equally well write the following:
long num1 =3D 1, num2 =3D 10, num3 =3D 100, num4 =3D 0;
num4 =3D (++num1, ++num2, ++num3);
The effect of this assignment would be to increment the variables num1, =
num2 and num3 by 1, and to set num4 to the value of the last expression =
which will be 101.=20
This example is aimed at illustrating the effect of the comma operator, =
and is not an example of how to write good code. As you can see, writing =
an assignment statement in this fashion can be very misleading.
----- Original Message -----=20
From: Sayajin=20
To: dev...@li...=20
Sent: Sunday, August 26, 2001 3:14 AM
Subject: [Dev-C++] Dev-c++ and array !
Hello everybody ! ! !
Very strange :
Dev-c++ accept the declaration "int Tab[10,10];" (it's not permitted =
Visual C++ and Borland C++ don't accpet it) but finally Dev-c++ ignore =
the first value so if we declare :=20
- "int Tab[10,2];" for Dev-c++ it means : "int Tab[2];"=20
Strange isnt'it ?=20
|