aspose file tools
The moose likes Product and Other Certifications and the fly likes Why prefix is faster than postfix Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Reply Bookmark "Why prefix is faster than postfix" Watch "Why prefix is faster than postfix" New topic
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
    
    3

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Why prefix is faster than postfix
 
Similar Threads
Unexpected output
In crement-Why is 'a' jumping to 102 instead of 101?
Need help with a++/b-- expression
Why is this printing 1,0 instead of 1,1
Operator question