C
Programming and Technical
Programming
Program
#include
int print(int n)
{
if(n==0)
return 0;
print(n-1);
printf("%dn",n);
}
int main()
{
int n=0,x=3;
n=print(x);
printf("%dn",n);
return 0;
}
explain the o/p?
Read Solution (Total 19)
-
- OUTPUT:
0n i.e.(zero n)
0n i.e.(zero n)
EXPLANATION:
n=print(x) in the main method which goes inside the method print(int n).
again there is a call for print method i.e.print(n=1). where n is decremented from 3 to 2, then 1, then 0.
within the print method, there is a printf statement.
within the main method, there is another printf statement.
so, 0n is displayed twice.. - 10 years agoHelpfull: Yes(2) No(1)
- 1n2n3nxxxxxn
function print return value by self call
print(3) return value 3.
print(2) return value 2.
print(1) return value 1.
print(0) return value 0.
finaly last value return by print function 0.
in main function return some garbage value becouse print function call itself many time or return different values. - 10 years agoHelpfull: Yes(2) No(0)
- can anyone give me the option of this question
- 10 years agoHelpfull: Yes(1) No(0)
- 0 0
i need some time - 10 years agoHelpfull: Yes(0) No(0)
- i think return 0 is after printf statement.. so ans is error..
- 10 years agoHelpfull: Yes(0) No(0)
- it will give an error
- 10 years agoHelpfull: Yes(0) No(0)
- 0, because print call itself again and again untill n becomes zero finally return n as 0
- 10 years agoHelpfull: Yes(0) No(0)
- on
n=0 it print 0value in printf statement n is there so it print (0n).
- 10 years agoHelpfull: Yes(0) No(0)
- answer will be 2 printed twice
explanation:-
- 10 years agoHelpfull: Yes(0) No(1)
- ans is 1n2n3n16384n
how it is possible. tell me kaushlesh kumar. - 10 years agoHelpfull: Yes(0) No(0)
- It will return 1
- 10 years agoHelpfull: Yes(0) No(0)
- n = print(3);
print(3) calls print(2) calls print(1) calls print(0)
ans : 0n - 10 years agoHelpfull: Yes(0) No(0)
- Output will be 1n2n3n2n
The last one will be 2n because every time the function returns it overwrites the last returned value of n. But when the function returns to its first call, it won't return any value and so the value returned to n in main will be 2. - 10 years agoHelpfull: Yes(0) No(0)
- plzz explain anyone...
print(3) from the main calls to print(2) calls to print(1) calls to print(0).
when it reaches to zero,(if(n==0) satisfied and return 0.), it first return 0 to print(1)(below the print(1) is printed, pf("%dn",1)) after it return to print(2)(below the print(2) is printed, pf("%dn",2)), after it return to print(3)(But here nothing below to print(3), bcz print(3) calling from the main()). so confusion is here. 1n2n but how 3n? plzz any one correct us. - 10 years agoHelpfull: Yes(0) No(0)
- o/p.
0
1
2
3
- 10 years agoHelpfull: Yes(0) No(0)
- 1n2n3nxxxxxn
function print return value by self call
print(3) return value 3.
print(2) return value 2.
print(1) return value 1.
print(0) return value 0.
finaly last value return by print function 0.
in main function return some garbage value becouse print function call itself many time or return different values. - 10 years agoHelpfull: Yes(0) No(0)
- itz 0 atlast step
as the function calls itself 3 times and everytime it decrements by 1 n atlast stops at n=0
so at n=0 it ll return 0 at final step.. - 10 years agoHelpfull: Yes(0) No(0)
- i think it is error because .there is no print in c .
- 10 years agoHelpfull: Yes(0) No(0)
- ans is 0 0
- 10 years agoHelpfull: Yes(0) No(0)
C Other Question