i have read in various places that functions which are declared in main() cannot be called outside main. But in below program fun3() is declared inside main() and called outside main() in other functions, and IT WORKS, giving output 64.here's link http://code.geeksforgeeks.org/7EZZxQ .however,if i change fun3() return type int to void ,it fails to compile,whats reason for this behaviour?
#include <stdio.h>
#include <stdlib.h>
int main()
{
void fun1(int);
void fun2(int);
int fun3(int);
int num = 5;
fun1(num);
fun2(num);
}
void fun1(int no)
{
no++;
fun3(no);
}
void fun2(int no)
{
no--;
fun3(no);
}
int fun3(int n)
{
printf("%d",n);
}
there is fail in compilation when declaration of fun3() is changed.
#include <stdio.h>
#include <stdlib.h>
int main()
{
void fun1(int);
void fun2(int);
void fun3(int); //fun3 return type changed to void error in compilation
int num = 5;
fun1(num);
fun2(num);
}
void fun1(int no)
{
no++;
fun3(no);
}
void fun2(int no)
{
no--;
fun3(no);
}
void fun3(int n) //fun3 return type changed to void error in compilation
{
printf("%d",n);
}
-Wall -Wextra -pedanticfor gcc), read up on what the compiler tells you and (may be) get enlightened.