Re: [algogeeks] Pre/Post L and r value
Yes, you are right. Pre increment simply increments and returns *reference*to same object. somewhat like: int& operator++(int &n){ n = n+1; return n; } On 31 October 2012 02:08, rahul sharma wrote: > @saurabh..thnxplz provide me code snippet for pre increment also..it > will help a lot..i can guess it will do n++ and return itself..plz give > code snippet... > > > On Mon, Oct 29, 2012 at 10:50 AM, Saurabh Kumar wrote: > >> 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 wrote: >> >>> But y post returns temp. object >>> >>> >>> On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar 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 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. >> > > -- > 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.
Re: [algogeeks] Pre/Post L and r value
@saurabh..thnxplz provide me code snippet for pre increment also..it will help a lot..i can guess it will do n++ and return itself..plz give code snippet... On Mon, Oct 29, 2012 at 10:50 AM, Saurabh Kumar wrote: > 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 wrote: > >> But y post returns temp. object >> >> >> On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar 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 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. > -- 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.
Re: [algogeeks] Pre/Post L and r value
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 wrote: > But y post returns temp. object > > > On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar 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 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.
Re: [algogeeks] Pre/Post L and r value
But y post returns temp. object On Fri, Oct 26, 2012 at 8:18 PM, Saurabh Kumar 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 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.
Re: [algogeeks] Pre/Post L and r value
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 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.
[algogeeks] Pre/Post L and r value
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.