Interview Questions

The predefined constant M_PI seems to be missing from my machines copy of math.h.

C Interview Questions and Answers


(Continued from previous question...)

The predefined constant M_PI seems to be missing from my machines copy of math.h.

That constant (which is apparently supposed to be the value of pi, accurate to the machine's precision), is not standard; in fact a standard-conforming copy of should not #define a symbol M_PI. If you need pi, you'll have to define it yourself, or compute it with 4*atan(1.0) or acos(-1.0). (You could use a construction like
#ifndef M_PI
#define M_PI 3.1415926535897932385
#endif

to provide your own #definition only if some system header file has not.)

(Continued on next question...)

Other Interview Questions