retagged by
206 views
2 votes
2 votes

What is the output of the below mentioned code snippet?

void goo(char *p)
{
if( p[0] = = ’\0’)
return;
goo(p+1);
goo(p+1);
printf("%c", p[0]);
}

main()
{
goo("123");
}
  1.     $3$ $3$ $2$ $1$ $3$ $2$ $1$
  2.     $3$ $2$ $3$ $1$ $3$ $2$ $1$
  3.     $3$ $3$ $2$ $3$ $3$ $2$ $1$
  4.     $3$ $3$ $3$ $1$ $3$ $3$ $2$
retagged by

1 Answer

Best answer
3 votes
3 votes
  •   goo(123)

        /                    \
 goo(23)                  goo(23)
  /        \                   /           \
goo(3)   goo(3)       goo(3)      goo(3)
 / \            / \               / \           / \     
goo( " " )  goo( " " )   goo( " " )  goo(" " )

goo(3)  return 3
goo(23)  return 2
goo(123)  return 1

so it returns  332 332 1 which is option C .

selected by
Answer:

Related questions

2 votes
2 votes
1 answer
1
0 votes
0 votes
1 answer
2
Bikram asked Feb 9, 2017
343 views
The following function finds the $GCD$ recursively. int GCD(int k, int u) { if( u = = 0 ) return k ; else return GCD( u , ____); }Fill in the blank with the most appropri...
3 votes
3 votes
3 answers
4
Bikram asked Feb 9, 2017
719 views
A radio is available at $\text{₹} 27780/-$ cash price, or three equal annual installments at $15\%$ per annum under $CI$ compounding annually. Each installment amount, ...