+ 3
Why output is 2 instead of 2 2
11 Réponses
+ 4
Yes. But in your version, it calls foo() ONE time. Defining it in main DOESN'T mean it is automatically called.
+ 5
Sagnik Ray void foo() isn't call !!! It's just prototype
+ 4
f() is called in main again, so it must have called foo ()??
+ 4
Call f() is only 1 time
+ 3
Not understand the problem. All is clear and easy
+ 2
#include <stdio.h>
int main()
{
void foo();
void f()
{
foo();
}
f();
}
void foo ()
{
printf ("2 ");
}
In the main function when you called "foo()" you used the "void" keyword.
So it is calling itself but not returns any value.
#include <stdio.h>
int main()
{
foo();
void f()
{
foo();
}
f();
}
void foo ()
{
printf ("2 ");
}
If you perform the above code it will print "2 2" instead of "2".
+ 2
Yeah Ural you are right its a prototype. But she didn't need to mention the prototype.
Instead if she calls foo() and f() both then the output is 2 2 and not 2 and she does not need to call f() two times.
And Now I understood the problem. Thank you.
+ 2
A little modification to the code to get output "2 2"
The Code:
#include <stdio.h>
int main()
{
int f()
{
if(foo()==NULL){
}
return 2;
}
int n = f();
printf(" %d",n);
}
void foo ()
{
printf ("2" );
}
In the above code you can call f() only once to get output "2 2"
Its just an alternative method.
+ 1
f() calls foo(), stop.
Or you call two times f(), or in f() you call two times foo()
https://code.sololearn.com/cqRr522H3H2E/?ref=app
0
#😎😎😎
#include <stdio.h>
int main()
{
void f()
{
foo();
}
f();
}
void foo ()
{
printf ("2 ");
main();
}
Try this
😎😎😎