Thread: Brilliant discoveries

  1. #1
    Confused Magos's Avatar
    Join Date
    Sep 2001

    Brilliant discoveries

    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.

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For my next brilliant question...
    By phosphorousgobu in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 02:49 PM
  2. ITT my holiday e-card for all in Brilliant GIMP graphics
    By Scourfish in forum A Brief History of
    Replies: 13
    Last Post: 12-25-2003, 02:01 PM
  3. brilliant code
    By Waldo2k2 in forum A Brief History of
    Replies: 35
    Last Post: 11-26-2002, 10:32 AM
  4. strcpy and strdup?
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 10-26-2001, 06:46 AM