Constants & Literals in C++

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this section of the C++ tutorial, we will have a look at the constants & literals in C++.

Constants in C++

Constant in C++ are similar to variables with exceptional properties. The value of the constant variable can’t be modified throughout the program. Its value is initialized at the time of declaration only.

Ways to define constants in C++:

  • Using #define preprocessor.


#define constexp 500;

  • Using the const keyword.


const int constexp = 500;

Literals in C++

In the C++ programming language, Literal is an object that depicts a fixed value in your C++ program.


double amount= 500.0;

Types of literals in C++:

  1. Integer literals
  2. Floating-point literals
  3. Boolean literals
  4. Character literals
  5. String literals

Leave a Comment

Your email address will not be published. Required fields are marked *