
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Enum vs Const vs #define in C/C++
Here we will see what are the differences between enum, const and the #define in C or C++ programs. These three creates some confusion while we have to take the decision for choosing them. Now let us see what are these three things.
const or static const
The const is constant type data, or static const is constant but storage specifier is static. So it will remain active until the program is terminated, and constant type data cannot be updated.
Example
#include <iostream> using namespace std; main() { int x; x = 65700; cout << "x is (as integer):" << x << endl; x = (short)65700; //will be rounded after 2-bytes cout << "x is (as short):" << x << endl; }
Output
x is (as integer):65700 x is (as short):164
Advertisements