Declaring function question

I prefer to declare all my functions before setup the have the function code at the end of the file (or wherever). Good or bad this is my approach.

Question on the syntax of declaring a function when passing variables.

for example:

int myFunction( int a, int b);

Is this function declaring the variable "a" as an int ? If I were to use the variable a somewhere else would there be a conflict?

When I research this syntax I can find no in depth info, just the statement of this syntax.

Thanks
John

For a prototype (aka "declaration"), which is what that is, the a and b are essentially ignored by the compiler. You can actually exclude them...

int myFunction(int, int);

Is this function declaring the variable "a" as an int ?

It declares that the first and second parameters are int. But nothing else.

1 Like

Hello JohnRob

Take a view to get some ideas and to gain the knowledge:

https://www.learncpp.com/cpp-tutorial/function-templates-with-multiple-template-types/

Yes, the variable will be local inside the function.

No, because the variable is local. If you have a global variable a in your code, the global variable will be masked by local inside the function, so you can' t access it.

Helpful, I think I have a better understanding now. Thanks