What will happen when a function defined within another function? What is the difference between code 1 and code 2?
CODE 1:
#include<stdio.h>
void m();
void main()
{
m();
void m()
{
printf("hi");
}
}
CODE 2:
#include <stdio.h>
void m();
void main()
{
void m()
{
printf("hi");
}
m();
}
When I compiled code 1 in gcc compiler, I got linkage error. But when I compiled code 2, I didn't get any error. I got output "hi". I want to know how compilation is done, when we write function definition within another function. I know that when we write function definitions not within another function, wherever be the function definition, we will not get any error when we call that function. for example see the below code:
CODE 3:
#include <stdio.h>
void m();
void main()
{
m();
}
void m()
{
printf("hi");
}
In code 3,even though I called the function before definition, it didn't show any error and I got output. Why it is not happening with code 1.