You need to link with the math library (use a ‘-lm’ on the command line). In the constant case, the compiler is probably being smart and precomputing sqrt(2.0) (so the code that is compiled is essentially ‘b = 1.414…;’)
More Related Contents:
- C Program will not compile [closed]
- function returns address of local variable, but it still compile in c, why?
- please help me to find the error in this C code [closed]
- “unknown type name ‘size_t'” error from included .cpp file, but removed when included file name changed to .h file. Why? [closed]
- Why does pow(n,2) return 24 when n=5, with my compiler and OS?
- Why do you have to link the math library in C?
- C compile error: “Variable-sized object may not be initialized”
- Recommended gcc warning options for C [closed]
- How to compile .c file with OpenSSL includes?
- Using pow() function throws undefined reference error in C
- No compiler error when fixed size char array is initialized without enough room for null terminator
- Why does gcc allow arguments to be passed to a function defined to be with no arguments?
- error C2275 : illegal use of this type as an expression
- Linking with gcc and -lm doesn’t define ceil() on Ubuntu
- sqrt from math.h causes linker error “undefined reference to sqrt” only when the argument is not a constant
- Why do you have to link the math library in C?
- c math linker problems on Ubuntu 11.10 [duplicate]
- dereferencing pointer to incomplete type
- How sqrt() of GCC works after compiled? Which method of root is used? Newton-Raphson?
- Can GCC not complain about undefined references?
- log(10.0) can compile but log(0.0) cannot with undefined reference?
- How do I return multiple values from a function in C?
- ?: ternary conditional operator behaviour when leaving one expression empty
- Segmentation fault handling
- How to iterate over a string in C?
- What is a “wide character string” in C language?
- Shellcode in C program
- Sending columns of a matrix using MPI_Scatter
- Does pthread_mutex_lock contains memory fence instruction? [duplicate]
- functions returning char pointer