Predefined function called before

I don’t understand how and when the call to this predefined function is made sqrt(), also if I define my own function sqrt(), it shows a compilation error, so why does the given function call work and call the user-defined function, although both codes are in the section (TEXT ) of my executable file.

#include<stdio.h>

int x = sqrt(16); 

int main()
{

     printf(" x =  %d\n",x);
     return 0;
}

OUTPUT:

x = 4;

When I call the sqrt () function defined by me, I get the following error, but the same error does not appear when I use the predefined function

ERROR: initialization element is not constant

+4
source share
6 answers

sqrt, , math.h, ergo .

, main x (, , ).

+8

C ( , , , x), . , , ( GCC) : initializer . , " ", , sqrt . , sqrt, .

++ , , , x.

+5

Gcc .

g++ ++.

g++, .

#include<stdio.h>
int mysqrt(int n)
{
return(n);
}
int a=mysqrt(10);

int main()
{
printf("%d",a);
return(0);
}

, mysqrt. .

, gcc.

6.6, 3

, , , - , , , .

.

,

, , , , .

gcc express, . express, . g++ ++ .

+1

, sqrt() else (math.h )

math.h, sqrt(), , ​​ .

, , ( , math.h)

my_sqrt(), , .

: . , , .

0

, , , .

, .

- , (#). . , - .

x , :

 #define x BLAH

, . Cheerss!

0

.

0

Source: https://habr.com/ru/post/1526141/


All Articles