Random code that crashes

lol. Just something I did in boredom, why doesn't it work, it keeps getting slower and slower and...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

unsigned long int n = 999999;

int main()
{
    cout << --n << endl;
    if(n == 0)
    {
        return 0;
    }
    main();
    return 0;
}
You shall not call main() inside of main().


Says the standard.
Last edited on
as firedraco siad You shall not call main() inside of main().

however check this out

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

unsigned long int n = 999999;

int main()
{
	for(;n!=0;--n)
	{
        cout << n << endl;
	}
    return 0;
}
Last edited on
Your stack will grow up rapidly. Depending on your operating system and its configuration the only limit may be the size of your hard disc if it may be used as a swap device or contains a swap file. This may slow down things...
Oh, my stack...that's why
Topic archived. No new replies allowed.