Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++

Question: 1 / 565

What keyword is introduced by C++ to avoid the problems of preprocessor #defines for value substitution?

const

When working with preprocessor #defines, there are a few common problems that can arise, such as lack of type checking and potential name clashes. To avoid these issues, C++ introduced the keyword "const", which allows us to declare constant values that cannot be changed at runtime.

Option B, enum, also allows us to associate names with constant values, but it does not provide the same level of type safety as const.

Option C, struct, is used to create custom data types, but it does not address the problems of preprocessor #defines.

Option D, define, is the preprocessor directive used to define macros, which are not a suitable alternative for avoiding the problems of #defines.

Hence, A is the correct answer as it was specifically introduced in C++ to address the issues with preprocessor #defines for value substitution.

Get further explanation with Examzify DeepDiveBeta

enum

struct

define

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy