| Author |
Why prefix is faster than postfix
|
Eliza sahoo
Greenhorn
Joined: Jan 28, 2010
Posts: 4
|
|
Prefix operation is faster and better than to postfix operation.
Now let us see how both postfix and prefix work.
// postfix
iterator operator++(int)
{
iterator _Tmp = *this;
++*this;
return (_Tmp);
}
// prefix
iterator& operator++()
{
_Ptr = _Acc::_Next(_Ptr);
return (*this);
}
note: one integer dummy variable is used in postfix operation in order to distinguish weather it is a postfix operation or prefix operation. This dummy variable is never used.
(refer prefix / postfix overloading).
hope it would be helpful to all of you.
Any suggestions are appreciated.
Thanks
Eliza
http://bit.ly/aeuBqg
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
|
Note that this might be so for C++, but not necessarily for Java.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Why prefix is faster than postfix
|
|
|