+ 1

What is the difference between SYMBOLIC CONSTANTs and CONSTANTs in c ...??

2nd Aug 2018, 4:04 PM
Ranjeet
Ranjeet - avatar
2 Answers
+ 4
AFAIK, both symbolic constants (macros) and const type qualifier are used for handling "Magic numbers" Âč in the codebase. The difference between them can be summarized as following: ●Their definition● Macro (symbolic constant) : Is defined as a preprocessor directive whose name is replaced by its body during the compilation stage. Macros neither have type nor any scope ( or you might say it's global ). That means, they can be accessible from everywhere in the code. Also, conventionally, their name is all uppercase and there's no semicolon terminator after each definition. Example: #define NAME "Reet" const qualifier : Pretty much the same as a normal variable, that is, unlike macro, it usually defines inside code blocks so their scope is limited to only that block. They also have explicit types which is a plus for type checking during compilation. Conventionally, their names begin with an uppercase letter. Example: const string Name = "Reet";
2nd Aug 2018, 9:29 PM
Babak
Babak - avatar
+ 3
Cont. _____ Âč https://en.m.wikipedia.org/wiki/Magic_number_(programming)
2nd Aug 2018, 9:29 PM
Babak
Babak - avatar