Showing posts with label pre-increment. Show all posts
Showing posts with label pre-increment. Show all posts

C++ or ++C (read i++ or ++i)

Pre-increment and post-increment : achieve "almost" the same end result with a little difference. It is always adviced to use the pre-increment form in expressions where you do not care what value the expression ought to use - the new incremented one or the older value prior to increment. Also when it matters, if you need the former then use the pre-increment form and if the latter use the post-increment form. That is the basic difference.

The post increment form has a drawback of generating a temporary (yeah, that can be optimized by the optimizer but still).

To understand the difference and when to use which form, you may find this Codeguru FAQ entry quite helping : C++ Operator: Why should I use '++i' instead of 'i++'?

Have fun!

Operator overloading basics

It is quite true that operator overloading looks such a big deal for beginners. I had my problems with that as well when I started with C++ and kept ignoring it considering it to be a complex thingie. But I tell you it is not. For an initial introduction to it, you may find this Codeguru FAQ entry quite useful : C++ Operator: How to deal with operator overloading?

Hope you find it interesting and easy to follow.

Keep rocking! Cheers!

Check out this stream