In c++ pre and post operator are used with variables where one need to just increment or decrement value by 1.For incrementing value ++ operator can be used and for decrementing -- operator can be used.
Its use is very simple one can easily say ++i or i++, to increment its value by 1. Many a times i found people very confused about it's usage (at beginners level) and some professional showing lots of concerns about its performance .That's what made me writing this post.
lets focus on its use first:-
One can now ask question that why there are two different version present for if we simply need to increment or decrement the value.
Lets take one example to see its effect in expression for post and pre increment operator :-
a) x = ++y; //pre increment
b) x = y++;//post increment
For above two expression value of x will be different. In expression (a) value of y would be incremented first then it would be assigned to x. And in expression (b), x would be assigned value of y first and then y would be increment. So if the value y is 5, then value of x would be 6 in expression (a) and its value would be 5 in expression (b).
We are now aware of its usage and impact in an expression, now lets find out which is better ?
To a much extent we can say that pre-increment is faster then post-increment operator. If we talk about independent statement containing just pre-increment and post-increment operator then pre-increment is faster (without compiler optmization).but, if we talk about integer variable the difference is almost negligible.It would be one or two cycle in unoptimized c++ code.As with pre-increment operator we did not need temporary location to store value, value is directly incremented and assigned where as in post-increment operator we need to store value in temporary variable. So with data type like integer, pointers no major performance can be achieved but if we talk about classes one should prefer use pre-increment operator.
Lets try to implement both operator it would help us gain understanding about it :- pre-increment operator
++i
int PreIncrement(int i)
{
i = i+1;//incrementing i
return i;
}
post-increment operator
i++
int PostIncrement(int i)
{
int tempvar = i;//temporary storage
i = i + 1;//incrementing i
return tempvar; //return tempvar
}
With above example its very clear that pre-increment is better and efficient then post-increment operator.
Again i want to make one point clear that it would not improve performance for data type like integers, pointer with advanced compiler you will not see any difference in assembly code too.I have written one test code to show this, lets look at it :-
With above disassembly code its clear that is no much impact on assembly instruction, code generated is almost same for both the cases.With all the analysis done so far, i am still thinking about post-increment operator.All points are going in-favor of pre-increment operator but there should be some benefit of post-increment operator too, where it can be used. Finally i found one such condition where post increment is better then pre-increment operator, lets look at following example :-
a) x = arrIntValues[i++]
b) x = arrIntValues[++i]
In above case expression (a) is better than (b) because in the second case,the address calculation of the array element has to wait for the new value of i which will delay the availability of x for one or two clock cycles.But it should be used cautiously since if you are making such changes in programs it may change code behavior.
Time to conclude now. As we have seen usage and comparison of pre/post increment operator, which shows that both are equally good if used for primitive data types with optimized compiler option.For non primitive data type one should use pre-increment operator. And finally it depends upon your code condition too, as we have seen one condition where post-increment is more efficient then pre-increment operator.Whole discussion is also applicable for pre/post decrement operator too.
I can’t stop myself writing on Sachin's 200, it’s a mmmmm what can I say just got spellbound from his performance.Its a magical mesmerizing memorable milestone performance from maestro the “Sachin Ramesh Tendulkar”.
Sachin slammed 200 not out today against one of the strongest ODI team South Africa at Captain Roop Singh Stadium Gwalior.
It’s a working day in our company and all are just busy with their scheduled work. And suddenly one guy screamed from his cube that “Sachin made 185 not out” this news just spreads like wildfire (technically like viruses on network). It infected almost every guy and all moved to our chill out zone which have television set. Quickly whole room got filled, each and every corner of room got occupied. All intellectuals who fights like anything in meeting rooms with their logical reasons were in total sync with each other and why not as all were talking about the “Sachin Tendulkar”. All guys present in room had several positive comments on Sachin,
all were busy in proving that "They are the biggest fan of Sachin" and everyone in thier heart wanted Sachin to cmake first ever double century in ODI.
Sachin crossed the magic number of 194 runs in 46th over and all went up clapping with a big smile on everyone's face.With this Sachin created a record of making a highest score in an ODI by breaking Saeed Anwar's record of 194 runs. But everyone was still holding breath eying for much bigger celebration.
Its now 47th over, Sachin reached 199 mark still requiring one golden run.We all were waiting for it and in next over we were hoping to see Sachin on strike but Dhoni faced all the 6 balls brilliantly and Sachin still on 199 mark :(. Despite Dhoni doing his job well, he was not getting any attention as everyone wanted to see Sachin on strike. And finally Sachin got strike in last over, Langeveldt the bowler, bowling 3rd ball of the last over, all stage set for Sachin to reach the milestone of double century. There was a complete silence in the room for a while, all praying for Sachin's 200. All were tensed but Sachin looking very confident and finally Langeveldt delivered the ball and Sachin guided ball for single run. All went up on their feet and this time celebration was much bigger and louder. Everyone were so happy and were feeling very proud. This moment will remain for a long time in memory of all the cricket lovers.
This event was so big that when i entered "Sachin's 200" search string on google search, it fetched almost 2400 pages within minutes of his double century.
Sachin got more then 70 records under his name, for detail check this link :-
Sachin is a living legend of cricketing world and adding to his greatness he dedicated this marvelous innings to Indian people.Sachin tussi great ho, jahanpanah tofah kabul karo :)
If you are a new blogger and want to get noticed on internet, then you can use google search engine for it.
Google search engine is the straight and most convincing way of attracting web traffic. Start writing good content , just be patient and surely your blog ranking will increase.
Follow below step to register it with google blog search :-
Google Buzz ?
The most buzzing event of Google nowadays and it’s also buzzing loud on all technical news too. Let’s find out what is so buzzing with it.
Google buzz is actually a smart way of short and sharper communication. The most attractive thing here is that it’s got integrated in your Gmail inbox, so don’t need to go onto some other link to access it.
Google Buzz is initiative toward getting strong in social networking domain. Currently Facebook covers almost 46% of the social network traffic, myspace 19% and you tube 14%. Google buzz can be said an answer to Facebook.
Google buzz comes with navigation in your gmail inbox. Buzz uses the people you email and chat with most often to build the first iteration of your network. This network was originally created by default and that is the biggest threat to privacy.Since Google buzz auto-follow people you communicate with on Gmail or Google Talk. Google buzz started with this issue and attracted lots of focus from the privacy organization. Many privacy organizations registered a strong concern over it. And Google buzz becomes the hot discussion topic of everyone. Every product tries to get focus with its new feature but Google buzz got the focus with its user privacy issue. Whatever Google buzz as a product ultimately attracted huge users and organization.
Finally Google apologizes for this and they have planned to launch it with more transparency and control features.It is still a mystery whether it’s all intended or a genuine user issue.
But overall Google buzz is a great feature to use; it helps one to share quickly text, videos and links with your network.
I have already starting buzzing with it and let’s see how far this feature will go.
Everyone wants to get noticed on Internet after launching very first content on new site :).
There are several ways by which one can get noticed on internet like search engines, backlinks, social networking sites, forums etc...I have explored search engine registration mechanism.
Its not very difficult to register your blog/website with famous search engine. Search engine are the most effective tool to get web traffic to your blogs/website. When it comes to search engine google, yahoo and msn live search are the most used option nowadays.
I have collected following links which can be used for submitting your URL :-
Above search engine shares 90% of all the hits. So registering to above link would be enough to get noticed at very first stage. Above links are easy mechanism to get yourself noticed, but they did not guarantee that your URL would come at top position in their searches. It all depends on the page rank, locality, back-links, content and several other factors, which guides search engines deciding priority of displaying pages.Let's have a brief of search engine working :- "Search engine have three basic module web crawling, indexing and searching.Web crawler collects information, then it get indexed based on several algorithms and searching retrieves relevant information from this indexed information".
I hope above information would be helpful if you are starting new website and want to to get noticed on internet.