static, define, and const in C
- by yCalleecharan
Hi, I've read that static variables are used inside function when one doesn't want the variable value to change/initialize each time the function is called. But what about defining a variable static in the main program before "main" e.g.
#include <stdio.h>
static double m = 30000;
int main(void)
{
value = m * 2 + 3;
}
Here the variable m has a constant value that won't get modified later in the main program. In the same line of thought what difference does it make to have these instead of using the static definition:
const double m = 30000;
or
#define m 30000 //m or M
and then making sure here to use double operations in the main code so as to convert m to the right data type.
Thanks a lot...