Remember
Register
1
new
Chill
new
Puzzles
new
GK
new
Sports
new
Business
Home
Questions
MCQs
Unanswered
Tags
Users
Ask a Question
Write Article
Articles
Connect to us
What is the benefit of using #define to declare a constant ? [CLOSED]
+4
votes
294
views
What is the benefit of using #define to declare a constant ? [CLOSED]
This question has an answer at:
What is the benefit of using #define to declare a constant?
c
c programming
posted
Dec 24, 2013
by
Prachi Agarwal
Looking for an answer? Promote on:
The #define directive is a preprocessor directive; the preprocessor replaces those macros by their body before the compiler even sees it. Think of it as an automatic search and replace of your source code.
A const variable declaration declares an actual variable in the language, which you can use... well, like a real variable: take its address, pass it around, use cast it, convert it, etc.
Oh, performance: Perhaps you're thinking that avoiding the declaration of a variable saves time and space, but with any sensible compiler optimisation levels there will be no difference, as constant values are already substituted and folded at compile time. But you gain the huge advantage of type checking and making your code known to the debugger, so there's really no reason not to use const variables.
...