C++ Variables and Constants

  • C++ is a strongly typed language because every variable must be declared with a data type.This variable cannot be later assigned a value of another data type.For example,if we declare an integer called int abc then, abc can only store integers.It cannot store any float values.

  • A C++ identifier is a name used to identify a variable, function, class,object or any other user-defined item.Variables are identifiers that the user defines or creates to store values.

  • A variable is essentially a named memory location.It is ‘named’ because the user gives a name according to his own discretion and a variable is nothing but a storage or a ‘memory location’ where data is stored.

  • A variable must be initialised with a data type.Initialising a variable is demonstrated by the following command:

    • int  a = 7;

Certain rules before choosing identifier names(or variable names) are as follows:

  • C++ is a case-sensitive language. That means that identifiers such as value,Value,VaLue are all different identifiers.

  • Identifiers can only contain letters , digits, and the underscore character.

  • An identifier can be started only with a letter or an underscore character. You cannot start the identifier with a digit.

  • C++ has a set of reserved keywords that cannot be used as identifiers.


  • A constant expression is a named memory location for a value. A constant expression cannot have its value changed in the program during run time.

  • C++ uses the keyword ‘const’ to indicate that an expression is a constant.

  • When  a constant is declared in C++, you must assign a literal value to that constant at the same time.  This cannot be assigned later or changed later in the code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: