Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

function prototypes in main or before main in C

Tags:

c

Should the function prototype in C be in main or before main. I was taught before main, but my friends class book shows it in main. Which is the correct way?

His book shows it:

int main()
{
    void numberTable();

    numberTable();
}

void numberTable()
{
    int num;
    ...rest of the code...
}
like image 659
shinjuo Avatar asked Oct 05 '11 05:10

shinjuo


1 Answers

Both are correct.
If you add the function declaration inside main, its scope is inside the main { }.
If you add it outside main, its scope is the entire source file.

like image 51
Alok Save Avatar answered Nov 09 '22 18:11

Alok Save