Hi, Can anybody tell me the diffrence between a variable/array declared as <static const> and a variable declared as <const>. Example: ===== static const int arr1[]={1,2,3,4,5,6,7}; const int arr1[]={1,2,3,4,5,6,7}; Thanks Biswajit
First I would like to know where you are declaring the static. Is in inside a function or a class member? But for some general explanation, when declared with static the variable becomes static and whose value is preserved through the program execution.
Are you writing to C99, and does your compiler support that? C89 does not support the "const" keyword.
no i m just writting that in VC++. Both the statements are written above all function defination in my .c file. i just want to know how compiler treats both these variables when it counters
Both are same as far as usage is concerned but the static variables are allocated in heap where as the other one is not.
"const" does not affect the static keyword. It is merely an instruction to the compiler that you should not be allowed to vary the value in your code. "Const" does not have any runtime effect. It's strictly a compile-time rule.
Y do u want to use const with static.. doesnt it defy the use of const at all.. y do u want to persist with value when it cannot be changed at all... as mentioned above by Dawei, const is just compile time variant of #define