3

If a function(say a()) prototype is declared inside a function(say main()) does it mean that it cannot be used in functions other that main() function?

0

3 Answers 3

3

No that does not mean that. If the other functions declare it too, then the function can be used by those other functions too.

int main(void) {
  void f(void); 
  f();
}

void g(void) {
  void f(void);
  f();
}

In this example, main declared function f locally and called it. But g does that same thing too. Both declarations refer to the same function.

Sign up to request clarification or add additional context in comments.

2 Comments

Well, you may as well declare it at outer unit scope if you are going to do that!
I mean, what you say is correct, but I can't help feeling it's not quite what the question was driving at, but then again, I could be wrong....
0

Yes that is correct. That is true for all declarations within a particular scope. They are only available within the defining scope.

Of course, you can declare the same function in another scope, but I don't think that's what you meant.

Comments

-1

In general things that you are able to declare inside a function (e.g. variables) are only in use for that function.

1 Comment

I think you are confused between declarations and definitions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.