can any one tell me can we declare a function in user defined function ? such as
int sum(int x, int y)
{
int fun( float x);
}
Can we define a function inside a function ? As I know we can't define a function inside a function.
But I just did this and its work fine the code is given below :
{
int main()
{
func1();
return 0;
}
func1()
{
int i = 0;
auto func2()
{
i = 10;
printf("Heloo i am func 2\n");
}
printf("Heloo i am func 1\n");
func2();
}
}
It works very fine .
Now can anyone tell me what is going around how a function inside a function is defined or working properly ?
Can anybody explain to me why the code is working ?
Now when I changed few lines of code it give me following problems The changes are following:
code:
{
func1()
{
func2();
int i = 0;
auto func2()
{
i = 10;
printf("Heloo i am func 2\n");
}
printf("Heloo i am func 1\n");
}
error:
error: static declaration of ‘func2’ follows non-static declaration
note: previous implicit declaration of ‘func2’ was here
Now what are these error and why are they coming ?
If I call func2() in main function than it will show an error like
undefined reference to func2
Now can anyone tell me what is wrong here ?