static, define, and const in C

Posted by yCalleecharan on Stack Overflow See other posts from Stack Overflow or by yCalleecharan
Published on 2010-04-09T21:29:36Z Indexed on 2010/04/09 21:33 UTC
Read the original article Hit count: 226

Filed under:
|
|
|

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...

© Stack Overflow or respective owner

Related posts about static

Related posts about c