Constants(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option A. -> L prefixIt can turn this as wide character instead of narrow characters.
Explanation:-
Answer: Option A. -> The first one refers to a variable whose identifier is x and the second one refers to the character constant xNone.
Explanation:-
Answer: Option C. -> Declares a constant a whose value will be 100Because the const is used to declare non-changable values only.
Explanation:-
Answer: Option D. -> They end with a semicolonNone.
Question 5.
What is the output of this program?
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
- 12.5664
- 13.5664
- 10
- compile time error
Explanation:-
Answer: Option A. -> 12.5664In this program, we are finding the area of the circle by using concern formula.
Output:
$ g++ cons.cpp
$ a.out
12.5664
Question 6.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int const p = 5;
6.
cout
- 5
- 6
- Error
- None of the mentioned
Explanation:-
Answer: Option C. -> ErrorWe cannot modify a constant integer value.
Explanation:-
Answer: Option C. -> literalsNone.
Explanation:-
Answer: Option D. -> all of the mentionedBecause these are the types used to declare variables and so these can be declared as constants.
Explanation:-
Answer: Option C. -> both a and bThe const will declare with a specific type values and #define is used to declare user definied
constants.