Featured Post

The bug in the name of the C++ language.

From the internet, a popular quote goes like this: 

"Of course, while it is true that the ++ operator gives the C++ language its name, it also led to the first joke about the language. C++ haters point out that even the name of the language contains a bug: 'After all, it should really be called ... ++C, because we only want to use a language after it has been improved.' "

We will now see why this joke is so absolutely hilarious. 



int main()
{
int x = 40;
int y = ++x + 1;
std::cout << x << '\n' << y;
}


Output: x = 41, y = 42.

The pre-increment operator first increments the value of (the ++) and then stores it in the variable. Hence, when the code is executed, x becomes 41 AFTER being assigned to .

The post-increment works the other way, the value is first stored in the lvalue before being assigned to the rvalue of the variable being incremented. 


int main()
{
int x = 40;
int y = x++ + 1;
std::cout << x << '\n' << y;
}


Output: x = 41, y = 41

So, technically:

C++ means: First use C and then increment it (improve it). 
++C means: First improve C and then use it. 

So, yes, it should have been ++C!

Comments

  1. This must have been the incrementation that is used in a loop.

    ReplyDelete
  2. maybe it could be that you should know the c language first and then increment it because c is a subset of c++

    ReplyDelete

Post a Comment

Let's discuss and learn more

Related Posts

Ex-HP CEO Hurd Pays $14 Million Bounty as Oracle Pledge Fee

Biography of The Rock 'n' Roll Drummer...John bonham....

Scrum Roles (Scrum Master, Product owner, Development Team) and collaboration between each other

Wi-Fi WPA2 Zero Day Vulnerability Found