PDA

View Full Version : Brilliant discoveries



Magos
09-16-2002, 04:29 AM
Post here if you have discovered something new about programming that you didn't know before.
It doesn't have to be something remarkable, just something that could be fun, interesting or so obvious that you didn't know it before.

Most of you probably know this, but...
I have found that the assignment operator returns the value that is assigned, ie:
Myvar = 34;

That is why you can do this:
if((FilePointer = fopen(...)) != NULL)

The assignment operator returns the value returned from fopen(), so that you can then can compare it with NULL.

This is also why several assignments on the same line works, ie:
MyVar1 = MyVar2 = MyVar3 = MyVar4 = 35;

Myvar4 = 35 returns 35, so the line is truncated to this:
Myvar1 = MyVar2 = MyVar3 = 35;

And so on until all variables has been assigned that value.

RoD
09-16-2002, 04:33 AM
cout <<iosetflags (ios::showpoint | ios::right | ios::setprecision(2)) <<endl;

shows the decimal point, aligns it to the right, and allows two number spots after the decimal.

I never knew that b4 the other day.