In the preceeding program why do "//Statements" run twice? How can I make it run only once?Code:#include <iostream.h> void recurse(int i) { if (i == 1) { i = 0; recurse(i); } //Statements } int main() { recurse(1); return 0; }
In the preceeding program why do "//Statements" run twice? How can I make it run only once?Code:#include <iostream.h> void recurse(int i) { if (i == 1) { i = 0; recurse(i); } //Statements } int main() { recurse(1); return 0; }
Replace <iostream.h> with:
Now, to your question, simply follow the calls:Code:#include <iostream> using namespace std;
> main
-> recurse (i = 1) [since i == 1, call recurse(i = 0)
--> recurse (i = 0) [i != 1, so don't call recurse again]
--> statements [from recurse(0), since recurse was not called again]
-> statements [from recurse(1), after the statements in the if-block have finished]
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Thanks for that. Here's another newbie question: What's the difference between <iostream> and <iostream.h>?Originally Posted by Zach L.