Some people say that is more right to write
thanCode:for(int i = 1; i < argc; ++i)
What is the reason for that? (if that is true).Code:for(int i = 1; i < argc; i++)
Some people say that is more right to write
thanCode:for(int i = 1; i < argc; ++i)
What is the reason for that? (if that is true).Code:for(int i = 1; i < argc; i++)
Can't see it makes any difference. According to H&S 5 the result of the third parameter is discarded.
There is no difference. It's just a matter of style preference.
If you understand what you're doing, you're not learning anything.
>What is the reason for that?
Assuming the compiler takes you literally and doesn't implement an optimization that even Dennis Ritchie's first compiler used, the first is better because it avoids a temporary for the intermediate value. In theory, it's possible for i++ to be implemented like this:
Whereas ++i can be implemented like this:Code:int save = i; i = i + 1; return save;
In reality, you probably won't see a compiler that fails to optimize both into the same machine code (for a standalone expression like the example). Miracle C might be one of those hypothetical bad compilers, but I don't know for sure because I avoid it like the plague.Code:i = i + 1; return i;
Use whichever you find clearer, but keep in mind that if you move to C++ there will be more of a difference because those operators can be overloaded. In such a case, it's better to use the prefix increment for class objects and whichever you want for built-in types.
My best code is written with the delete key.
Thanks for the answers guys.