0% found this document useful (0 votes)
39 views4 pages

Bhumi Programming

The document discusses constants and variables in C++ programming. It defines a variable as a storage area that holds data, and each variable needs a unique name (identifier). Rules for naming variables include only allowing letters, numbers, and underscores, and variables cannot begin with a number. It also defines constants as variables whose value cannot be changed, using the const keyword to declare them. An example shows declaring and attempting to change a constant named LIGHT_SPEED results in an error.

Uploaded by

bmeghani2611
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Bhumi Programming

The document discusses constants and variables in C++ programming. It defines a variable as a storage area that holds data, and each variable needs a unique name (identifier). Rules for naming variables include only allowing letters, numbers, and underscores, and variables cannot begin with a number. It also defines constants as variables whose value cannot be changed, using the const keyword to declare them. An example shows declaring and attempting to change a constant named LIGHT_SPEED results in an error.

Uploaded by

bmeghani2611
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ST.

PAUL INSTITUTE OF PROFESSIONAL


STUDIES INDORE

SESSION 2022-23
CLASS : BCA 1 YEAR
SUBJECT : PROGRAMMING
METHODOLOGY
AND DATA STRUCTURE
TOPIC : CONSTANTS AND VARIABLES

SUBMITTED BY :
SUBMITTED TO :
MS BHUMI MEGHANI
PROF. HEMA BHARDWAJ
ROLL NO. 9
C++ 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). For example,
int age = 14;
Here, age is a variable of the int data type, and we have assigned an
integer value 14 to it.

Rules for naming a variable


•A variable name can only have alphabets, numbers, and the underscore _.
•A variable name cannot begin with a number.
•It is a preferred practice to begin variable names with a lowercase
character. For example, name is preferable to Name.
C++ Constants

In C++, we can create variables whose value cannot be changed.


For that, we use the const keyword. Here's an example:

const int LIGHT_SPEED = 299792458;


LIGHT_SPEED = 2500 // Error! LIGHT_SPEED is a constant.

Here, we have used the keyword const to declare a constant named


LIGHT_SPEED. If we try to change the value of LIGHT_SPEED, we
will
get an error.
THANK YOU

You might also like