Originally Posted by
rosemary
Could you explain more?
This is legal ...
Code:
void swap(int x, int y); /* Function declaration - legal. Visible to all subsequent functions in this source file */
int main()
{
void swap(int x, int y); /* function declaration - legal. Only visible inside main() */
int a = 3, b = 2;
swap(a,b); /* call the swap() function. */
}
but this is not ....
Code:
void swap(int x, int y); /* function declaration - legal */
int main()
{
int a = 3, b = 2;
swap(a,b); /* call the swap() function. OK */
void swap(int x, int y) /* function definition inside a function. Illegal! */
{ /* whatever implementation */};
}
Note that, in this post, I have not corrected the swap() function so things it does are visible to the caller. The arguments of swap() need to be pointers, not of type int.