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

Ex:
#include<stdio.h>
int  add(int a,int b)
{    

return a+b; }

Main()
{
int i=10,j=20,k;
K=add(i,j) ;
Printf("%d",k);}
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.
...