Constants in CPP (C Plus Plus)

By Prof. Fazal Rehman Shamil
Last modified on October 9th, 2019

Constants in CPP (C Plus Plus)


The difference between variables and constants is that variables can change their value at any time but constants can never change their value.

Tips for Constant variable

  •     Constants are also called literals.
  •     Constants can be any of the data types.
  •     It is considered the best practice to define constants using only upper-case names.

There are two methods for a constant variable in C++

1.    By using the const keyword 

const type constant_name;

Example with the const keyword

 2.    By using #define Preprocessor keyword 

#define constant_name;
Example with #define keyword
Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.