ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
When you use #define, all the constants get replaced with their actual values before compilation by the preprocessor, where as a const variable is implmented as a variable and you get the the overhead associated with implementing a normal variable.
FYI const variables can be globally defined aswell
You said that #define makes constants global, and you can declare const variables local, you never said they could be global aswell, but maybe you were implying that? it wasn't clear to me which is why I added the last line in my previous post
"#define" is useful where memory is constrain... like RTOS.. because it will not get store in memory. if memory is not a constrain than u can use either of these. But u can use pointer to the constant variable while to define u cant. using pointer to the constant variable u can even change the data bt u cant change the data of the defined one because it never stores in memry.