sqrt() function not working with variable arguments

Use the command gcc -Wall -o "test2" "test2.c" -lm which will likely fix this.

This includes the math library in addition to the standard C runtime library. On most systems, the math library is historically a separate entity that needs to be explicitly requested.


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...;')


In case of gcc you need to link the library.

gcc filename.c -lm .

However in case of g++ no need to link the library so this will work fine :

g++ filename.c -o filename Once compilation is successful.

To run simply enter ./filename in G++. and enter ./a.out in Gcc.