Why the reverse output?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2006
Posts: 2
Reputation: nwiner is an unknown quantity at this point 
Solved Threads: 0
nwiner nwiner is offline Offline
Newbie Poster

Why the reverse output?

 
0
  #1
Aug 1st, 2006
  1. #include <iostream.h>
  2. int fred[] = { 11, 22, 33, 44 };
  3. int *fp;
  4. int main(int argc, char *argv[])
  5. {
  6. for (int i=0; i<argc; i++)
  7. cout << argv[i];
  8. cout << endl << "Hello world." << endl;
  9. fp = fred;
  10. cout << *fp++ << *fp++ << *fp++ << *fp++ << " - Why is this?" << endl;
  11. fp = fred;
  12. cout << fp[0] << fp[1] << fp[2] << fp[3] << endl;
  13. fp = fred;
  14. cout << *fp++;
  15. cout << *fp++;
  16. cout << *fp++;
  17. cout << *fp++;
  18. cout << endl;
  19. fp = fred;
  20. for (i=0; i<4; i++)
  21. cout << *fp++;
  22. cout << endl;
  23. return 0;
  24. }
  1. /* output<blockquote> COUTTRY.EXEonetwothree
  2. Hello world.
  3. 44332211 - Why is this?
  4. 11223344
  5. 11223344
  6. 11223344
  7. </blockquote>*/
Thanks
Last edited by WolfPack; Aug 1st, 2006 at 1:40 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Why the reverse output?

 
1
  #2
Aug 1st, 2006
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Why the reverse output?

 
0
  #3
Aug 1st, 2006
> Why the reverse output?
Make sure you understand the consequences of the link posted by WaltP

Even though you might be able to come up with an explanation of why the output is reversed, there is no telling what would happen in any similar circumstance.

Undefined behaviour is very specific, anything at all can happen and the problem is solely with your code. It is not a language issue or a compiler issue.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2
Reputation: nwiner is an unknown quantity at this point 
Solved Threads: 0
nwiner nwiner is offline Offline
Newbie Poster

Re: Why the reverse output?

 
0
  #4
Aug 1st, 2006
Thanks lots... I'm embarrassed, I should have known...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC