[cs13001] Lab 6 problem

Mikhail Nesterenko mikhail at cs.kent.edu
Fri Feb 21 21:45:57 EST 2014


> > 
> > In your for-loops, replace commas with semicolons.
> > 

Actually, this brings up an interesting topic. In C++, there is an
occasionally used comma-operator. The operator is this

	     A, B

The operator evaluates the first operand, discards its value, then
evaluates the second operand and returns its value.

It is often use in for-loops to declare and maintain multiple loop
variables. What do you think this code prints?

	   int i, j;
	   for(i=0, j=0; i + j < 10; i++, j++)
	   	   cout << i << j;	

Thanks,
--
Mikhail


More information about the cs13001 mailing list