+ 2
What will be the output of the following code..?Also plz include steps in your answer...
#include <iostream> void e(int) ; int main() { int a=3; e(a); return 0; } void e(int n) { if(n>0) { e(--n); cout <<n; e(--n); } }
6 Respuestas
+ 1
Your 'extra' zero is display 7 lines from bottom because n was high enough for the line 16 call to actually enter it's if.
+ 2
A compiler error as e is undefined where you call it in main.
+ 2
Thanks John Wells ...
+ 1
I have edited my code
John Wells...
+ 1
Line 8 calls e with 3.
Line 14 is true (nested e level 1).
Line 16 changes n to 2 and calls e with 2 (1).
Line 14 is true (2).
Line 16 changes n to 1 and calls e with 1 (2).
Line 14 is true (3).
Line 16 changes n to 0 and calls e with 0 (3).
Line 14 is false (4).
Line 20 exits e (4).
Line 17 displays 0 (3).
Line 18 changes n to -1 and calls e with -1 (3).
Line 14 is false (new 4).
Line 20 exits e (4).
Line 20 exits e (3).
Line 17 displays 1 (2).
Line 18 changes n to 0 and calls e with 0 (2).
Line 14 is false (new 3).
Line 20 exits e (3).
Line 20 exits e (2).
Line 17 displays 2 (1).
Line 18 changes n to 1 and calls e with 1 (1).
Line 14 is true (new 2).
Line 16 changes n to 0 and calls e with 0 (2).
Line 14 is false (new 3).
Line 20 exits e (3).
Line 17 displays 0 (2).
Line 18 changes n to -1 and calls e with -1 (2).
Line 14 is false (new 3).
Line 20 exits e (3).
Line 20 exits e (2).
Line 20 exits e (1).
Line 10 exits program