dimanche 28 juin 2015

scope of function declaration in c

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://ift.tt/1eRZPmy .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);
}

Aucun commentaire:

Enregistrer un commentaire