![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 2
| Code: { int myInt;
myInt = 5;
printf( "myInt++ ---> %d\n\n++myInt ---> %d", myInt++, ++myInt);
}
"myInt++ ---> 5 ++myInt ---> 7" but it actually gave: "myInt++ ---> 6 ++myInt ---> 7" with a warning: operation on 'myInt' may be undefined. Can some one help me out? I'm so confused by the result and the warning message. |
| firebird is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,356
| Read this C FAQ on expressions.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #3 |
| and the hat of sweating Join Date: Aug 2007 Location: Toronto, ON
Posts: 3,120
| Changing a variable more than once in a single statement is undefined. |
| cpjust is offline | |
| | #4 |
| Registered User Join Date: May 2008
Posts: 2
| Thank you guys very much. |
| firebird is offline | |
![]() |
| Tags |
| postfix, prefix, printf |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is prefix faster than postfix? | dwks | C Programming | 6 | 07-28-2005 11:51 AM |
| stacks postfix aww fooey | drdodirty2002 | C++ Programming | 3 | 09-25-2004 10:00 AM |
| postfix and prefix | drdodirty2002 | C++ Programming | 8 | 09-24-2004 06:26 AM |
| postfix and prefix...??? | matheo917 | C++ Programming | 8 | 04-20-2002 01:19 PM |
| Data Structures / prefix and postfix | rickc77 | A Brief History of Cprogramming.com | 1 | 12-08-2001 12:48 PM |