c programming :Variables, Constants and literals

preview_player
Показать описание
Variables
In programming, a variable is a container (storage area) to hold data.

To indicate the storage area, each variable should be given a unique name (identifier). Variable names are just the symbolic representation of a memory location. For example:

int playerScore = 95;
Here, playerScore is a variable of int type. Here, the variable is assigned an integer value 95.

The value of a variable can be changed, hence the name variable.

char ch = 'a';
// some code
ch = 'l';
Rules for naming a variable
A variable name can only have letters (both uppercase and lowercase letters), digits and underscore.
The first letter of a variable should be either a letter or an underscore.
There is no rule on how long a variable name (identifier) can be. However, you may run into problems in some compilers if the variable name is longer than 31 characters.
Literals
Literals are data used for representing fixed values. They can be used directly in the code. For example: 1, 2.5, 'c' etc.

Here, 1, 2.5 and 'c' are literals. Why? You cannot assign different values to these terms.
Constants
If you want to define a variable whose value cannot be changed, you can use the const keyword. This will create a constant. For example,

const double PI = 3.14;
Notice, we have added keyword const.

Here, PI is a symbolic constant; its value cannot be changed.

const double PI = 3.14;
PI = 2.9; //Error
You can also define a constant using the #define preprocessor directive.
#variables #constants #literals #coperators
Рекомендации по теме
visit shbcf.ru