Qbasicnews.com

Full Version: fast code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
what is faster

++$i;

or

$i++;
The same. But they act differently.
The issue occurs when done in comparisons or in situations not on their own, for example:

x = i++;

Would cause a different result than:

x = ++i;

For example:

Code:
#include <iostream>
using namespace std;
int main() {
int x = 3;
int z = x++;
cout << z << endl;
x = 3;
z = ++x;
cout << z << endl;
}

Prints:

3
4
3?? why is not 4? what is the point of x++; ?

Anonymous

i know jack about c++, but it appears the comparison is done before the incrementation, thats all.
thats what i thought but it seems to be worhtless then.
Quote:3?? why is not 4? what is the point of x++; ?

I use x++ more than ++x in for loops because it mimics the way FB/QB do for next loops
If the pluses are first, the variable is increased first (before the value of it is returned), if they are after, the variable is increased after the value is returned.
++c is called prefix increment
c++ is called postfix increment

As their "naming" suggests, ++c increments before assigning (returning) the value of c while c++ does the exact opposite. Similarly we have decrement operators too...
We?

You got a frog in your pocket?
Pages: 1 2