856 views
1 votes
1 votes

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?

Please log in or register to answer this question.

Related questions

0 votes
0 votes
2 answers
1
AJAY KUMAR ARYAN asked May 24, 2016
442 views
I have read in theory that multiple aggregation = innermost aggregation ,So I was expecting result as min(price)BUTwhen I run this program on www.w3school.com <SQL ...
0 votes
0 votes
2 answers
2
GateAspirant999 asked May 11, 2016
1,830 views
What is the time complexity of the following function: function(n) { for(i = 0; i < n; i = i*2) { for(j = 0; j < i; j++) { printf("*"); } } }
1 votes
1 votes
1 answer
3
Aditya Bahuguna asked Jan 4, 2018
448 views
0 votes
0 votes
0 answers
4
Nishi Agarwal asked Mar 10, 2019
512 views
A(n){if(n<1) return (1);else return A(n-2)+B(n-1);}B(n){if(n<=1) return 1;else return B(n-1)+A(n-2);}