Post increment returns temp object because it has to return the old value of object not the new incremented one: Simply put, the code for post increment somewhat goes like this:
int operator++ (int &n){ int temp = n; n = n+1; return temp; } that's also the reason you cannot use it as a lvalue in an exprression, as you would be assigning nowhere. On 27 October 2012 20:09, rahul sharma <rahul23111...@gmail.com> wrote: > But y post returns temp. object > > > On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar <srbh.ku...@gmail.com>wrote: > >> i++: Post increment can't be a lvalue because Post increment internally >> returns a temporary object (NOT the location of i) hence you cannot assign >> anything to it. The result of i++ can be used only as a rvalue. >> ++i: whereas, in Pre-increment value gets incremented and the same >> location is returned back to you, hence can be used as lvalue in an >> expression.(C++ allows this) >> Both can be used as rvalues though. >> >> On 26 October 2012 18:54, rahul sharma <rahul23111...@gmail.com> wrote: >> >>> why pre inc. is l value and post is r value..please explain >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.