c - can't we use same variable name as a function? -
here code..it giving segmentation fault error...please tell me why...in small program taking 1 function add() , 1 variable int add. , inside main function creating function pointer of add() , trying print value of add variable. giving error...plz tell me why??
#include<stdio.h> float add(int , float); int main() { float (*fp)(int , float); float result; int add=10; fp = add; result = fp(5 , 9.9); printf("%f\n",result); printf("%d\n",add); return 0; } float add(int ,float b) { return + b; }
global names shadowed local names.
so, when mention add
in main
, try take add
declared in main
first.
when giving fp = add
assigning integer (int add = 10
) function pointer. , trying call address. invalid address (10
), got segmentation fault.
Comments
Post a Comment