i defined a function without declaring it, yet it was working, why?

0 votes
asked Nov 10, 2019 by wardha

2 Answers

+2 votes
answered Nov 11, 2019 by DeathBringer269 (180 points)

This is because the function definition itself can act as an implicit function declaration. It will work fine if you write your function definition above main. If you write it below then your program will run but you will get a warning. 

Function declaration is required when you define a function in one source file and you call that function in another file. In such case, you should declare the function at the top of the file before calling the function.

+1 vote
answered Nov 11, 2019 by Rohan Ghobade (520 points)
If you wrote the definition before the main means first it will treated as function declaration after calling it will execute

I hope u wrote code like this

int  add(int a,int b)

return a+b; }

int i=10,j=20,k;
K=add(i,j) ;
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.