Extra brackets with function names in C/C++
Consider below C program. The program has extra bracket around function name.
#include <stdio.h>
void (foo)( int n)
{
printf ( "Function : %d " , n);
}
int main()
{
(foo)(4);
return 0;
}
|
Output:
Function 4
So putting extra bracket with function name works in C/C++.
What can be use of it?
One use could be, if we have a macro with same name as function, then extra brackets avoid macro expansion wherever we want the function to be called.
#include <stdio.h>
#define foo(n) printf("\nMacro : %d ", n);
void (foo)( int n)
{
printf ( "Function : %d " , n);
}
int main()
{
(foo)(4);
foo(4);
return 0;
}
|
Output:
Function 4
Macro : 4
Last Updated :
21 Jun, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...