Generating combinations of n elements in groups of k
Main loop could be simplified a little

There's not too much to say about the current program.  It works and it seems like it is using the fastest method possible.  It basically adds one to the last array element and moves left when an "overflow" happens.  At the end of handling all the "overflows", it moves back to the right, resetting each digit.

The one thing that I would change is basically that when you are moving back to the right, there's no need to use the main loop to do that.  It causes extra compares of (p &gt;= 0) which are always going to be true and extra ++a[p] which are unnecessary.  You could instead handle moving to the right in its own nested loop.  Here's how it would look like:

do {
    if (++a[p]&gt;n-k+p) {
        // Overflow, move to the next element on the left.
        p--;
        continue;
    }
    // Resolve overflows by resetting digits to the right.
    while (p &lt; k-1) {
        a[p+1]=a[p]+1;
        p++;
    }
    newCombo(a,n,k);
} while(p&gt;=0);


An interesting challenge

What if I asked you to write a program that prints out the N'th combination instead of all of them.  In your given example with n=6 and k=4, the 0th combination would be 0 1 2 3 and the 14th (and last) combination would be 2 3 4 5.  I find this task to be much more difficult (and useful) than generating all combinations.