I made a struct Triangle and I made a function to calculate p(perimeter/2).
When I call the function inside printf it works.
But when I call the same function as a simple arithmetic statement it doesn’t work and gives me following error
called object 'p' is not a function or function pointer
Source code:
#include <stdlib.h>
typedef struct{
int a, b, c;
} Triangle;
int perimeter (Triangle t){
return t.a + t.b + t.c;
}
float p (Triangle t){
return perimeter(t) / 2.0;
}
int main() {
Triangle t = {3, 4, 5};
//float p = p(t);
printf("p = %.2f\n",p(t));
return 0;
}
>Solution :
The line
float p = p(t);
defines a local variable p which shadows the global function p. This variable is of type float, so it is not a function or pointer.
Rename the variable to fix this.