Symbolic Constant Conundrum
The article discusses the concept of symbolic constants in programming languages, particularly C and C++. It explains various methods for defining constants, including macros, enumerations, const, and constexpr. The author concludes by recommending the best practices for using these different types of constants in programming.
- ▪A symbolic constant is a name that stands for a literal value in programming languages.
- ▪C and C++ have evolved to include multiple ways to specify symbolic constants, such as macros and constexpr.
- ▪Using constants is preferred over magic numbers for better code readability and maintainability.
Opening excerpt (first ~120 words) tap to expand
try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 2304) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } Paul J. Lucas Posted on May 23 Symbolic Constant Conundrum #c #cpp Introduction A symbolic constant in any programming language is a name — a symbol — that can be used to stand in for a constant — a literal value. Programming languages inherited symbolic constants from mathematics that has many of them grouped by specific field of study. Examples include: π (pi), c (speed of light), e (Euler’s number), G (gravitational constant), h (Plank’s constant), etc.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).