Sunday, July 8, 2012

Recursion with main()

Lurking in my filesystem I found some code. Some time ago I've tried call main recursively. I not finished this code then.
Surprisingly, main not differ to other functions (except it is a 'enter point' for program). Code below compiles with "hard" gcc flags and successfully works (echoing given arguments).

#include <stdio.h>

int main(int argc, char *argv[]) {
    if (argc > 1) {
        printf("%s\n", argv[1]);
        main(argc - 1, argv + 1);
    return 0;

No comments:

Post a Comment