Thursday, 26 May 2016

Whether Calling a function without function declaration in C or C++ is allowed?

 
Whenever you call a c function or C++ function, compiler will expect the function definition or function prototype as declaration.
Whether C or C++ programming will allow calling the function without function declaration?

Example program:

int main()
{
myFunction(); //calling without pre declaration,
  return 0;
}
int myFunction()
{
  return 0;
}
Answer is yes in case of C programming(Terms and condition will apply) and answer is no for C++ programming.

Calling function in C programming function declaration:


Function with return type as integral value no need to be declared or defined explicitly in the C programming.  
So then what is that terms and conditions?
When your return type is  not a integral value, then you have to explicitly define  or  declare the function . If it is not defined then compiler will throw an error like, I can’t found “function declaration” or “function definition” for the function you called.

Calling function in C++ programming function declaration:


For c++ it will not compile for all return types irrespective of the return type of the function