250+ TOP MCQs on Constants and Answers

This section on online C++ test on “Constants”. One shall practice these test questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our online C++ test questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of online C++ test questions on “Constants” along with answers, explanations and/or solutions:

1. The constants are also called as _____________
a) const
b) preprocessor
c) literals
d) variables
Answer: c
Clarification: Other name for Constants are literals.

2. What are the parts of the literal constants?
a) integer numerals
b) floating-point numerals
c) strings and boolean values
d) all of the mentioned
Answer: d
Clarification: Because these are the types used to declare variables and so these can be declared as constants.

3. How are the constants declared?
a) const keyword
b) #define preprocessor
c) both const keyword and #define preprocessor
d) $define
Answer: c
Clarification: The const will declare with a specific type value and #define is used to declare user-defined constants.

4. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int  const  p = 5;
  6.         cout << ++p;
  7.         return 0;
  8.     }

a) 5
b) 6
c) Error
d) 8
Answer: c
Clarification: We cannot modify a constant integer value.

5. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     #define PI 3.14159
  4.     int main ()
  5.     {
  6.         float r = 2;
  7.         float circle;
  8.         circle = 2 * PI * r;
  9.         cout << circle;
  10.         return 0;
  11.     }

a) 12.5664
b) 13.5664
c) 10
d) 15
Answer: a
Clarification: In this program, we are finding the area of the circle by using concern formula.
Output:

$ g++ cons.cpp
$ a.out
12.5664

6. Which of the following statement is not true about preprocessor directives?
a) These are lines read and processed by the preprocessor
b) They do not produce any code by themselves
c) These must be written on their own line
d) They end with a semicolon
Answer: d
Clarification: No terminating character required for preprocessor directives statements.

7. Regarding the following statement which of the statements is true?

const int a = 100;

a) Declares a variable a with 100 as its initial value
b) Declares a construction a with 100 as its initial value
c) Declares a constant a whose value will be 100
d) Constructs an integer type variable with an as identifier and 100 as the value
Answer: c
Clarification: Because the const is used to declare non-changeable values only.

8. The difference between x and ‘x’ is?
a) The first one refers to a variable whose identifier is x and the second one refers to the character constant x
b) The first one is a character constant x and the second one is the string literal x
c) Both are same
d) Both are string literal
Answer: a
Clarification: In a C++ code, names with quotes like ‘x’ represent a character or string(in case of a collection of characters) whereas without quotes they represent an identifier.

9. How to declare a wide character in the string literal?
a) L prefix
b) l prefix
c) W prefix
d) Z prefix
Answer: a
Clarification: It can turn this as the wide character instead of narrow characters.

  C++ Programming Questions and Answers – Integer Types and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top