Prepare
Practice
Interview
Aptitude
Reasoning
English
GD
Placement papers
HR
Current affairs
Engineering
MCA
MBA
Online test
Login
Constant variables can be created in CPP
Home
>>
Category
>>
C++ (MCQ) questions and answers
>>
C++ basic concepts
Q. Constant variables can be created in CPP by using ________ .
- Published on 19 Oct 15
a.
enum
b.
const
c.
#define
d.
All of these
e.
None of these
ANSWER: All of these
Related Content
Constructor and Destructor (
10
)
Operator Overloading (
11
)
Inheritance (
16
)
Polymorphism and Abstract Classes (
12
)
C++ basic concepts (
39
)
Exception Handling (
22
)
File Handling (
11
)
Functions (
20
)
Memory Management (
6
)
Pointers (
3
)
Discussion
Nihal
-Posted on 08 Oct 15
You can declare constant variable by using enum, const, #define.
enum Color { RED, GREEN, BLUE };
int main() {
Color c;
c = RED;
cout << "RED = " << c << endl;
c = GREEN;
cout << "GREEN = " << c << endl;
c = BLUE;
cout << "BLUE = " << c << endl;
return 0;
}
Output:
RED = 0
GREEN = 1
BLUE = 2
const keyword is used to make a variable constant. You cannot change its value.
.Another mechanism to define constant values is the use of preprocessor
#define PI 3.14159
➨
Post your comment / Share knowledge
Required!
Required!
Invalid Email Id!
Required!
Enter the code shown above:
Please enter the code shown above
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)
MCQs
English
Tutorials
Download
▲