Thread: Question 26 Answer seems wrong on site quiz

  1. #1
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656

    Question 26 Answer seems wrong on site quiz

    Code:
    What is the outcome of running the following code: int c=0; cout<<c++<<c;
    
    Undefined
    01
    00
    I tried out the program and I keep getting 01...
    Code:
    psycho@Shiva:~/Programming/Laboratory$ g++ -ansi -pedantic -Wall coutUndefined.cpp
    psycho@Shiva:~/Programming/Laboratory$ ./a.out
    01

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    I believe what is ment by Undefined, is its not stated specificly in the standard what will come out, so it can vary from compiler to compiler, and/or platform to platform. Basicly, you will never know the exact outcome, so don't expect what you got to be the same as what some one else would.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I tried out the program and I keep getting 01...
    You misunderstand the nature of "undefined".
    http://www.eskimo.com/~scs/C-faq/q11.33.html
    This specifically includes all your expected answers, and a whole bunch of other outcomes as well.

    And yes, that quiz question has the right answer.
    http://www.eskimo.com/~scs/C-faq/s3.html
    You'll always come unstuck if you try and do too much with the increment and decrement operators.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ! C question: what is wrong with this ?
    By aaronc in forum C Programming
    Replies: 1
    Last Post: 04-28-2004, 12:29 AM
  2. 5am question: What did i do wrong.
    By Geolingo in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2003, 04:30 AM
  3. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM
  4. Why did I get this question wrong?
    By DISGUISED in forum C++ Programming
    Replies: 6
    Last Post: 01-31-2002, 04:15 PM
  5. Replies: 1
    Last Post: 01-23-2002, 03:34 AM