![]() |
| ||
| Re: i++ and ++i void main() { int i=3; printf("%d,%d,%d",i,i++,++i); getch(); } o/p: 5,4,4 if we r using ++i it will increment and it will asign to i so ans is 4 if we r using i++ it will increment but it assign to i so ans is 4 b'coz of i++ i value is 5.for clarifications execute the program |
| ||
| Re: i++ and ++i Not only is your example horribly broken, it's not even a valid example of the point you're trying to make. >void main() Implementation-defined behavior. main is required to return int. >printf("%d,%d,%d",i,i++,++i); Undefined behavior. The commas in an argument list do not constitute sequence points, and ++ modifies its operand. Undefined behavior. You didn't include stdio.h, and functions that take variable arguments require a prototype in scope. >getch(); Implementation-defined behavior. You didn't include a header that declares getch, and getch isn't a standard function. |
| ||
| Re: i++ and ++i Haahaa, good one Narue, But hell yeah that example will only give out errors. Btw, balu116, please use the code tags. Posting source code like that is rude. |
| ||
| Re: i++ and ++i When did this become the noob gets it wrong thread? It seems a magnet for 1-post people to chip in with their "interpretation" only to be corrected for getting some aspect of "side effect" or "sequence point" wrong. |
| ||
| Re: i++ and ++i xD but it can't be helped but corrected. Since others who are new here might get it wrong (which happens a lot). A good code writing practice is always appreciated. |
| All times are GMT -4. The time now is 6:05 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC