
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
- Related Articles
- "static const" vs "#define" vs "enum" ?
- Const vs Static vs Readonly in C#
- Const vs Let in JavaScript.
- Compare define() vs const in PHP
- C++ vs C++0x vs C++11 vs C++98
- Virtual vs Sealed vs New vs Abstract in C#
- C++ vs Java vs Python?
- Tokens vs Identifiers vs Keywords in C++
- Regular cast vs. static_cast vs. dynamic_cast in C++
- Regular cast vs. static_cast vs. dynamic_cast in C++ program
- Abstract vs Sealed Classes vs Class Members in C#
- C++ vs C#
- Value parameters vs Reference parameters vs Output Parameters in C#
- OneDrive vs Dropbox vs Google Drive vs Box
- fseek() vs rewind() in C

Advertisements