What are different types of constants in C++?


There are no types of constants in C++. It's just that you can declare any data type in C++ to be a constant. If a variable is declared as constant using the const keyword, you cannot reassign its value. 

Example

#include<iostream>
using namespace std;
int main() {
   const int i = 5;
   // Now all of these operations are illegal and
   // will cause an error:
   i = 10;
   i *= 2;
   i++;
   i--;
   //...
   return 0;
}

Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician

Updated on: 11-Feb-2020

512 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements