Question:

How are the constant declared ?

Show Hint

Prefer using the \text{const} keyword over \text{\#define} for declaring constants. \text{const} variables are type-checked by the compiler and respect scope, which can prevent subtle bugs that \text{\#define} might cause.
  • Const keyword
  • \#define preprocessor
  • Both (A) and (B)
  • S define
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Understand what a constant is in programming. A constant is a value that cannot be altered by the program during its execution.
Step 2: Analyze the declaration methods in languages like C and C++.

(A) \text{const} keyword: This is the modern, preferred way. It creates a typed, read-only variable. For example: \text{const float PI = 3.14159;}
(B) \text{\#define} preprocessor: This directive is used to define macros. Before compilation, the preprocessor replaces every occurrence of the macro with its value. For example: \text{\#define PI 3.14159}. While it achieves a similar result, it's a simple text substitution without type checking.
Since both \text{const} and \text{\#define} are valid methods for creating constants in languages like C/C++, the correct option is (C).
Was this answer helpful?
0
0