C++ Variables, Keywords and Constants

Like any other language, C++ has its own vocabulary and grammar. In this tutorial, we will discuss the concept of a variable and its types as they relative to the C++ programming language.


In C++ Programming, keywords are said to be reserved words whose has a fixed meaning and these meaning cannot be changed. But it tells the compiler what to do. Keywords are always in lowercase letters. It cannot be used as an identifier.

Some common keywords are:-

  • break
  • if
  • else
  • while
  • for
  • do
  • goto
  • jump
  • void


Identifier refers to the name it may be the name of variable, function, and arrays. These are user-defined names and consist of a sequence of letters and digits. underscore character is also permitted as an identifier. Spaces, punctuation marks, and symbols cannot be part of an identifier.

For example:-


The C++ language is a “case sensitive” language. That means that an identifier written in capital letters is not equivalent to another one with the same name but written in small letters.


A variable is a data name that may be used to store a data value. It may take different values at different times during execution.

For example,


Here, rollno is a variable of the int data type, and we have assigned an integer value 1 to it.

Obviously, this is a very simple example, since we have only used one small integer value, but consider that computers can store millions of numbers like these at the same time.

Rules for naming a variable

  • A variable name can only have alphabets, numbers, and underscore (_).
  • A variable name must not have a decimal point.
  • A variable name cannot be a keyword. For example, char is a keyword that is used to denote character.
  • No commas or blanks are allowed within an integer constant
  • It can be started with an underscore. However, it’s not considered a good practice.