• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Why prefix is faster than postfix

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
No thanks. We have all the government we need. This tiny ad would like you to leave now:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic