|
INTERVIEW QUESTIONS
C
VARIABLES IN C
DETAILS
Question: What is the benefit of using const for declaring constants?
Answer: The benefit of using the const keyword is that the compiler might be able to make optimizations based on the knowledge that the value of the variable will not change. In addition, the compiler will try to ensure that the values won’t be changed inadvertently.
Of course, the same benefits apply to #defined constants. The reason to use const rather than #define to define a constant is that a const variable can be of any type (such as a struct, which can’t be represented by a #defined constant). Also, because a const variable is a real variable, it has an address that can be used, if needed, and it resides in only one place in memory
|
|
|
Category |
Variables in C Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 8448 users |
Added on |
10/22/2009 |
Views |
75817 |
Rate it! |
|
|
Question:
What is the benefit of using const for declaring constants?
Answer:
The benefit of using the const keyword is that the compiler might be able to make optimizations based on the knowledge that the value of the variable will not change. In addition, the compiler will try to ensure that the values won’t be changed inadvertently.
Of course, the same benefits apply to #defined constants. The reason to use const rather than #define to define a constant is that a const variable can be of any type (such as a struct, which can’t be represented by a #defined constant). Also, because a const variable is a real variable, it has an address that can be used, if needed, and it resides in only one place in memory Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
What is the benefit of using #define to declare a constant?
|
View Answer
|
|
What is the benefit of using an enum rather than a #define constant?
|
View Answer
|
|
What is storage class and what are storage variable ?
|
View Answer
|
|
What are the advantages of auto variables?
|
View Answer
|
|
Differentiate between an internal static and external static variable?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Variables in C Interview Questions & Answers - Exam Mode /
Learning Mode
|