Why the output 332? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
16th Dec 2019, 6:01 PM
Hima
Hima - avatar
17 Answers
+ 3
~ swim ~ Thank you..
17th Dec 2019, 8:59 AM
Jayakrishna 🇮🇳
+ 3
~ swim ~ If I'm wrong anywhere please correct me, pointers are tough to understand by me
17th Dec 2019, 9:23 AM
Jayakrishna 🇮🇳
+ 3
~swim~ Thanks again..
17th Dec 2019, 9:29 AM
Jayakrishna 🇮🇳
+ 2
int main(){ f("123"); } void f(char a[]) //a[]="123" (1) { if(a[1]=='\0') //a[]=2 return; }f(a+1); //a[]="23". (2) f(a+1); //a[]="3". (3)(4) printf("%c", a[1]); } (4) for this does nothing but returns to same function. after competing inner loops. (3)for this, after completing inner loops control backs here, and Now a[]=23 so a[1]=3; (2)same way, for this now a[1]=3 (1)and for this now a[1]=2 So output is 332
16th Dec 2019, 6:23 PM
Jayakrishna 🇮🇳
+ 2
First f("123") This call is completed after 3 more times f() call completed. See f("123") has to call f("a+1") and f("a+1"). In this first f("a+1") call again f("a+1") call after it completion of execution. So totally 4 times f executed. Read comments...
16th Dec 2019, 6:47 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna I need both.
16th Dec 2019, 8:11 PM
Hima
Hima - avatar
0
Jayakrishna how does the last recursion a[]="3" print 3?
16th Dec 2019, 6:40 PM
Hima
Hima - avatar
16th Dec 2019, 6:49 PM
Hima
Hima - avatar
0
After completion of a function execution control comes after the next statement so there is another time f() needed to execute. First main calls F(123)=>f(23), => f(23)=>f(3)<= ^ =>f(3)<=return when ever function call another function, the values are pushed in to the stack. So fisrt f("123") ,a=123 when it calling f(a+1), ,f("123"), and a=123 ,are pushed unto stack. f(a+1) ,a=23, pushed to stack. again recursivly calls f(a+1), this goes on until a[1]=='\0'. 2nd f(a+1) does same with a=23 Now, stack contains retyrning, 23 23 123 poped of ,completing last function completing first until first call f("123") So 23 =>a[1] =3 23= >a[1]=3 123=>a[1]=2
16th Dec 2019, 6:55 PM
Jayakrishna 🇮🇳
0
Hima see this. May be You can understand clearly what happening.. Hoping this give you clear explanation. Reply after for any.... https://code.sololearn.com/c9SbCgm6Giym/?ref=app
16th Dec 2019, 7:00 PM
Jayakrishna 🇮🇳
16th Dec 2019, 7:01 PM
Hima
Hima - avatar
0
Hima Did you understand completely the previous one? If you don't understand in some where, reply that. I may missed some point there. I will reframe and reply. Some of those are confused ones.. So reply if you don't understand.
16th Dec 2019, 7:26 PM
Jayakrishna 🇮🇳
0
Jayakrishna I got it. ty:
16th Dec 2019, 8:03 PM
Hima
Hima - avatar
0
Run the last one i updated. What about second one? What you need from that? Output? Or explanation?
16th Dec 2019, 8:10 PM
Jayakrishna 🇮🇳
0
~ swim ~ (struct name*)0; converts int 0 to explicit (struct name*) what it means ? What it pointing to then? And (*(*int)) ? Ponter to pointer convertion? Is it possible?
16th Dec 2019, 9:24 PM
Jayakrishna 🇮🇳
17th Dec 2019, 9:19 AM
Jayakrishna 🇮🇳
0
Well, I got no idea.
18th Dec 2019, 2:31 AM
YoungZartash
YoungZartash - avatar