Thursday, July 30, 2009

In C can we declare (not using) functions inside the main()?

In C can we declare (not using) functions inside the main()?





like this :





int main()


{


int data_load(char string[Rows][atrbs][len], int *, int *, char title[atrbs][len]);


int check_all_positive(char string[Rows][atrbs][len], int, int);


int check_all_negative(char string[Rows][atrbs][len], int, int);

In C can we declare (not using) functions inside the main()?
no, you can't - not in C. in C++ it's valid.





write the declaration before the function head:





int data_load(char string[Rows][atrbs][len], int *, int *, char title[atrbs][len]);


int check_all_positive(char string[Rows][atrbs][len], int, int);


int check_all_negative(char string[Rows][atrbs][len], int, int);


int main()


{


}
Reply:Not because the functions are global, before or after main(){}
Reply:You can declare functions within other functions. Your declaration will be valid to whatever scope it is declared in. This means you can declare a function as you did in main. Of course, the declaration will only be valid within main.





The keyword is declare. I don’t recall function definitions within functions being valid syntax. Either way, everything I said is verifiable with a few minutes of time, a plain text editor, and a standards compliant C compiler. Turn on all warnings, and ISO-conformity, and test out what I said. There’s your answer.

our song

No comments:

Post a Comment