C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-16-2005, 02:47 PM   #1
UT2004 Addict
 
Kleid-0's Avatar
 
Join Date: Dec 2004
Posts: 645
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
Kleid-0 is offline   Reply With Quote
Old 04-16-2005, 03:01 PM   #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.
Xipher is offline   Reply With Quote
Old 04-16-2005, 03:03 PM   #3
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,676
> 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.

Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
! C question: what is wrong with this ? aaronc C Programming 1 04-28-2004 12:29 AM
5am question: What did i do wrong. DeepBlackMagic C++ Programming 2 10-10-2003 04:30 AM
what does this warningmean??? kreyes C Programming 5 03-04-2002 07:53 AM
Why did I get this question wrong? DISGUISED C++ Programming 6 01-31-2002 04:15 PM
Ok, long code...and really short and quick Question and most probably answer. incognito C++ Programming 1 01-23-2002 03:34 AM


All times are GMT -6. The time now is 09:31 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22