| | |
i++ and ++i
![]() |
He's referring to the way you write them when you wish to overload the operators.
http://www.parashift.com/c++-faq-lit...html#faq-13.14
However,
1. He's 3 years too late with the information.
2. It's off topic as the thread was about how the prefix and postfix forms affect integers, and not about how to write overload versions.
http://www.parashift.com/c++-faq-lit...html#faq-13.14
However,
1. He's 3 years too late with the information.
2. It's off topic as the thread was about how the prefix and postfix forms affect integers, and not about how to write overload versions.
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
//Lets declare i, and set it equal to 4.
int i = 4;
//Now say their is a function nammed goFetch(int), and we wanted to pass an increment of i to it
//i = 4 before this code gets touched, the value 4 would be passed, and then i would become 5
goFetch(i++);
//i = 4 before this code gets touched, i gets incrimented before anything else (and becomes 5), and the value 5 would be passed
goFetch(++i);
So, ++i means to incriment first then give the incrimented value, and i++ means to give the original value, then incriment.
Hi,
As i++ is used in a statement, then the valude of i in the statement, remains same ie unincremented. But after the statement, this is incremented.
When ++i, is used then it is incremented with in the statement it self.
bye
>>and in the case of ++i;
>>the loop starts from 1,
No it doesn't -- the loop still starts with 0 because the i is not incremented until after the iteration of that loop finishes.
>>the loop starts from 1,
No it doesn't -- the loop still starts with 0 because the i is not incremented until after the iteration of that loop finishes.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
i++ first takes the value of i and then gives the increment----(POST INCREMENT OPERATOR) whereas ++i first gives the increment to the assigned i value---(PRE INCREMENT OPERATOR)
example::: i=6
i++ takes i and then gives increment i.e.,i++=5 but the compiler stores the value as 6 which is not the displayed output
++i gives increment first i.e., ++i=6...
input: enter an int:5
output:5
7
HERE THE VALUE OF ++i IS 7 COZ THE COMPILER STORES THE VALUE OF i++ AS 6...
example::: i=6
i++ takes i and then gives increment i.e.,i++=5 but the compiler stores the value as 6 which is not the displayed output
++i gives increment first i.e., ++i=6...
C Syntax (Toggle Plain Text)
void main() { int i,x,y; printf("enter an int:"); scanf("%d",&i); x=i++; y=++i; printf("%d\n%d",x,y); getch(); }
output:5
7
HERE THE VALUE OF ++i IS 7 COZ THE COMPILER STORES THE VALUE OF i++ AS 6...
Last edited by Ancient Dragon; Oct 7th, 2007 at 7:14 am. Reason: add code tags
•
•
•
•
WTF.. All she asked was the difference between ++i and i++, not such weird details.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Don't mean to hijack this thread, but yes there may be a difference, but then again there might not be one also. depends on the compiler, which I'm sure you already know but other readers may not.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Other Threads in the C Forum
- Previous Thread: Compiling Multiple files in a single Project
- Next Thread: Information on function pointers
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






