

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What are constants in C++?
A constant in C++ is a variable/named value that you just want to assign a value to it once and never let it change again in the execution of that program. For example, if you're writing an application that uses the value of pi in a variable PI. You would never want to let this value change. Declaring this value as a const will prevent it's reassigning throughout the program.
You can define constants in C++ by adding the const qualifier before the declaration of the variable.
Example
#include<iostream> using namespace std; int main() { const int x = 9; x = 0; return 0; }
This will define the constant variable x. But it will throw an error as we are trying to rewrite the value of a constant.
- Related Questions & Answers
- What are C++ Integer Constants?
- What are C++ Character Constants?
- What are Enumerated Constants in C++?
- What are C++ Floating-Point Constants?
- What are different types of constants in C++?
- What are Backslash character constants in C language?
- Are there constants in JavaScript?
- What are different types of constants in C language?
- What are the constants with an example in C language?
- What are constants in Kotlin and how to create them?
- What are various inbuilt methods used to access constants database in scipy.constants() module?
- PHP Constants
- Difference between C++ string constants and character constants
- Decimal constants in C#
- Mathematical Constants in Python
Advertisements