I don't understand how and when the call to this pre-defined function sqrt()
is made, also in case if i define my own function sqrt()
it shows a compilation error, so why a pre-defined function call works and call to user-defined function fails although both code resides in the (TEXT) section of my executable.
#include<stdio.h>
int x = sqrt(16);
int main()
{
printf(" x = %d\n",x);
return 0;
}
OUTPUT:
x = 4;
When i am calling sqrt() function defined by me i am getting following error but the same error does'nt show up when i am using a pre-defined function
ERROR : initializer element is not constant
If you define your own sqrt
function, it will clash with the one already defined in math.h
, ergo the error.
The call is made because globals (or, rather, namespace scope variables) are initialized before entry to main
- the initialization of x
that is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With