Machine-translated by Google. Questions are authored in English.
Top

Discussion

How are the constants declared?

  • A.const keyword
  • B.#define preprocessor
  • C.both const keyword and #define preprocessor
  • D.$define

Answer: C

Correct answer: both const keyword and #define preprocessor

Both mechanisms are used, and they work quite differently. #define is a preprocessor directive performing textual substitution before compilation: the name has no type, no scope and no address, and the compiler never sees it.

const qualifies an actual object, which has a type, obeys the ordinary scoping rules, occupies storage and is visible to the debugger. const is generally preferred for that reason, though #define is still needed where a value must be a constant expression usable in contexts such as an array bound in older C.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.