While it's not asked for, this seems to cry out for a compile-time solution:
template< int I >
struct increment { static const int result = I+1; };
std::cout << increment<41>::result << '\n';
That struct
is what's called a meta-function. Yes, it's a struct, but it's used (at compile-time) like a function: you call it, passing a parameter, and you get back a result. The syntax is hilarious, but that's because nobody actually planned to do this; the possibility was discovered (more or less) by accident.
Doing this at compile-time has the advantage that the result is a compile-time constant and can be used as such:
int my_array[increment<7>::result]; // array of 7+1 ints
Of course, defining an array like this is nonsense. Just as in run-time algorithms, incrementing is usually just one operation of an algorithm that computes something more complex.