Function declaration

what is the need of function declaration c programming language?

Comments

  • I think the declaration is needed so the compiler knows the function exist. So you usually need a declaration if you are calling a function in your code before it's actually defined OR if the definition of the function is in a different, usually file, scope.

  • We define a function and then call that function when we need, these things are not enough for telling the compiler about function existence ?

  • yes if you define it before you call it, it's fine, that is, define it earlier in the file. - however if you call it earlier in your code than you defined it then you need to declare it OR if your definition lies in a different file, you need to declare it in a header file and #include that header file in the .c/.cpp file you wish to call that function.

    I think the C compiler goes once through your code, it doesn't do multiple passes, so declaring it is like a promise to the compiler that you will define it later but in declaring the function you tell the compiler enough important info for it to type check your usages of that function...

  • thnxxxx for your advice

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories