Function is a variable so declaration of a function precede function definition,SO
#include<stdio.h>
main( )
{
void m( )
{
printf ( "hi" ) ;
}
m();
}
output: hi "Works correctly"
but if
#include<stdio.h>
main( )
{
m();
void m( )
{
printf ( "hi" ) ;
}
}
throws error because:
1)we have to define a function before calling it.
2)No prototype is declared before using it,so by default compiler will assume that there will be a function in below lines with return type "int" but thats not the case so type mismatch.
but if I decalre the prototype then,
#include<stdio.h>
void m();
main( )
{
m();
void m( )
{
printf ( "hi" ) ;
}
}
againg error:undefined reference to m
WHY?
last what I tried,removed the overhead of nested function
#include<stdio.h>
main( )
{
m();
}
void m( )
{
printf ( "hi" ) ;
}
there is type mismatch so it must throw error.BUT it runs correctly Why?