Q 1. The constants are also called as _____________
A. const
B. literals
C. preprocessor
D. variables
Show Answer
Answer:-B. literalsExplanation
Other name for Constants are literals.Q 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
Show Answer
Answer:-D. all of the mentionedExplanation
Because these are the types used to declare variables and so these can be declared as constants.Q 3. How are the constants declared?
A. const keyword
B. #define preprocessor
C. both const keyword and #define preprocessor
D. $define
Show Answer
Answer:-C. both const keyword and #define preprocessorExplanation
The const will declare with a specific type value and #define is used to declare user-defined constants.Q 4. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int const p = 5;
cout << ++p;
return 0;
}
A. 5
B. 6
C. 8
D. Error
Show Answer
Answer:-D. ErrorExplanation
We cannot modify a constant integer value.Q 5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
#define PI 3.14159
int main ()
{
float r = 2;
float circle;
circle = 2 * PI * r;
cout << circle;
return 0;
}
A. 12.5664
B. 13.5664
C. 10.9960
D. 15.4536
Show Answer
Answer:-A. 12.5664Explanation
In this program, we are finding the area of the circle by using concern formula. Output: $ g++ cons.cpp $ a.out 12.5664Q 6. Which of the following statement is not true about Pre-processors Directives?
A. These are lines read and processed by the pre-processor
B. They end with a semicolon
C. These must be written on their own line
D. They do not produce any code by themselves
Show Answer
Answer:-B. They end with a semicolonExplanation
No terminating character required for preprocessor directives statements.Q 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
Show Answer
Answer:-C. Declares a constant a whose value will be 100Explanation
Because the const is used to declare non-changeable values only.Q 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
Show Answer
Answer:-A. The first one refers to a variable whose identifier is x and the second one refers to the character constant xExplanation
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.Q 9. How to declare a wide character in the string literal?
A. W prefix
B. l prefix
C. L prefix
D. Z prefix
Leave a Reply