It's interesting to know how this code is working...? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

It's interesting to know how this code is working...?

#include <stdio.h> //int rec(int x);// to remove warning please un-comment this int main() { int a=5,fact; fact=rec(a); printf ("Factorial value = %d", fact); return 0; } int rec(x) //how this line is working? int x; { int f; if(x == 1) return (1); else f=x*rec (x-1); return (f); } https://code.sololearn.com/cTG4wwyR4aBh/?ref=app https://code.sololearn.com/cTG4wwyR4aBh/?ref=app

1st May 2022, 6:29 AM
Ur-Wellwisher
Ur-Wellwisher - avatar
2 Answers
+ 4
The syntax is an ancient way of declaring a function. int rec(x) int x; { ... } is equivalent to int rec(int x) { ... }
1st May 2022, 2:18 PM
Brian
Brian - avatar
+ 2
Definition of function "rec()" should write before main() function, if You don't want to write function Prototype [ i.e. int rec(int x); ]. And Run It. Then You will get Output without Warnings.
2nd May 2022, 9:21 AM
Rudra
Rudra - avatar