Thursday 21 April 2016

C++ - Constants Questions and Answers


1.  The constants are also called as
A. const
B. preprocessor
C. literals
D. none of the mentioned


Answer: Option C


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: Option D

Explanation:

Because these are the types used to declare variables and so these can be declared as constants.


3.  How the constants are declared?
A. const keyword
B. #define preprocessor
C. both a and b
D. None of the mentioned

Answer: Option C

Explanation:

The const will declare with a specific type values and #define is used to declare user definied constants.


4.  What is the output of this program?
#include
using namespace std;
int main()
{
int  const  p = 5;
cout << ++p;
return 0;
}
A. 5
B. 6
C. Error
D. None of the mentioned

Answer: Option C

Explanation:

We cannot modify a constant integer value.


5.  What is the output of this program?
#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.566
B. 13.566
C. 10
D. compile time error


Answer: Option A

Explanation:

In this program, we are finding the area of the circle by using concern formula.


6.  Which of the following statement is true about preprocessor directives?
A. hese 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: Option D



7.  Regarding 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 a as identifier and 100 as value


Answer: Option C

Explanation:

Because the const is used to declare non-changable 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 second one is the string literal x
C. Both are same
D. None of the mentioned


Answer: Option A

Explanation:

The first one refers to a variable whose identifier is x and the second one refers to the character constant x


9.   How to declare a wide character in string literal?
A. L prefix
B. l prefix
C. W prefix
D. none of the mentioned


Answer: Option A

Explanation:

It can turn this as wide character instead of narrow characters.

No comments:

Post a Comment