Bradmont2
06-08-2001, 01:09 PM
Since yoos guys apparently didn't see my question in the string reversal thread, I'll ask it here. Can you recurse main() in C/C++?
|
Click to See Complete Forum and Search --> : Can you recurse main()? Bradmont2 06-08-2001, 01:09 PM Since yoos guys apparently didn't see my question in the string reversal thread, I'll ask it here. Can you recurse main() in C/C++? The_Stack 06-08-2001, 01:55 PM Sure, but you'll blow up your stack. :) Strike 06-08-2001, 01:56 PM Sure you can, compile this: main() { static int counter = 10; if (counter == 0) exit(0); printf("%d\n", counter); counter--; main(); } This is a good example of a static variable too :) Bradmont2 06-08-2001, 02:14 PM qool, thanks. Can you use the int main (int argc, char * argv[]) header for main with recursion too? kmj 06-08-2001, 02:18 PM why don't you try it? Bradmont2 06-08-2001, 03:09 PM I will. ;) Strike 06-08-2001, 05:40 PM int main(int argc, char *argv[]) { static int counter = 10; if (counter == 0) exit(0); printf("counter = %d\n", counter); counter--; main(argc, argv); } Nifty and neat, no? justlinux.com
Copyright Internet.com Inc. All Rights Reserved. |