SlideShare a Scribd company logo
1 of 3
Download to read offline
www.cppforschool.com
Variable : Memory Concept
Programs shown in the previous section print text on the screen. This section
will introduce the concept of variable so that our program can perform
calculation on data.
Program : Adding two numbers
We'll solve this problem in C++ with the following steps:
STEP 1 : Allocate memory for storing three numbers
STEP 2 : Store first number in computer memory
STEP 3 : Store second number in computer memory
STEP 4 : Add these two numbers together and store the result of the addition
in a third memory location
STEP 5 : Print the result
STEP 1 : Now first we'll allocate memory for storing numbers.
Location of the computer memory which is used to store data and is given a
symbolic name for reference is known as variable. We need three variables, two
for storing input and third for storing result. Before a variable is used in a
program, we must declare it. This activity enables the compiler to make
available the appropriate type of location in the memory.
Following statements declare three variables of type integer to store whole
numbers.
int x;
int y;
int z;
You can declare more than one variable of same type in a single statement like :
int x, y, z;
STEP 2 : Following statement stores value in first variable
x = 25;
STEP 3 : Following statement stores value in second variable
y = 10;
STEP 4 : Now, add these two numbers together and store the result of the
addition in third variable
z = x + y;
STEP 5 : Print the result
cout << "The sum is ";
cout << sum;
You can combine above two statements in one statement
cout << "The sum is " << sum;
here, is the complete program
#include <iostream>
using namespace std;
int main()
{
//declare variables of integer type
int x;
int y;
int z;
//storing value in variables
x = 25;
y = 10;
//adding numbers and store the result in sum
z = x + y;
//print the result
cout << "The sum is ";
cout << z;
return 0;
}
Output : The sum is 35
Identifiers
Symbolic names can be used in C++ for various data items used by a
programmer in his program. A symbolic name is generally known as an
identifier. The identifier is a sequence of characters taken from C++ character
set. In previous program x, y and z are identifiers of variables. The rule for the
formation of an identifier are:
 An identifier can consist of alphabets, digits and/or underscores.
 It must not start with a digit
 C++ is case sensitive that is upper case and lower case letters are
considered different from each other.
 It should not be a reserved word.
Keywords
There are some reserved words in C++ which have predefined meaning to
compiler called keywords. These words may not be used as identifiers. Some
commonly used Keywords are given below:
asm auto bool break case
catch char class const const_cast
continue default delete do double
dynamic_cast else enum explicit export
extern false float for friend
goto if inline int long
mutable namespace new operator private
protected public register reinterpret_cast return
short signed sizeof static static_cast
struct switch template this throw
true try typedef typeid typename
union unsigned using virtual void
volatile wchar_t while

More Related Content

What's hot (19)

Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
Assignment7
Assignment7Assignment7
Assignment7
 
ICP - Lecture 6
ICP - Lecture 6ICP - Lecture 6
ICP - Lecture 6
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
 
First c program
First c programFirst c program
First c program
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
Moving Average Filter in C
Moving Average Filter in CMoving Average Filter in C
Moving Average Filter in C
 
C rules
C rulesC rules
C rules
 
Assignment10
Assignment10Assignment10
Assignment10
 
keyword
keywordkeyword
keyword
 
Function
FunctionFunction
Function
 
L03vars
L03varsL03vars
L03vars
 

Similar to Chapter 3 - Variable Memory Concept

Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptxDineshDhuri4
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions khawajasharif
 
CHAPTER-2.ppt
CHAPTER-2.pptCHAPTER-2.ppt
CHAPTER-2.pptTekle12
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2Don Dooley
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteachingeteaching
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfAbrehamKassa
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++DSCIGDTUW
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...bhargavi804095
 
Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03hassaanciit
 

Similar to Chapter 3 - Variable Memory Concept (20)

keyword
keywordkeyword
keyword
 
Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptx
 
Declaration of variables
Declaration of variablesDeclaration of variables
Declaration of variables
 
Chapter2
Chapter2Chapter2
Chapter2
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions
 
CHAPTER-2.ppt
CHAPTER-2.pptCHAPTER-2.ppt
CHAPTER-2.ppt
 
Chap 3 c++
Chap 3 c++Chap 3 c++
Chap 3 c++
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Pengaturcaraan asas
Pengaturcaraan asasPengaturcaraan asas
Pengaturcaraan asas
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdf
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++
 
C++ programming
C++ programmingC++ programming
C++ programming
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
 
Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03
 

More from Deepak Singh

Computer networks - CBSE New Syllabus (083) Class - XII
Computer networks - CBSE  New Syllabus (083) Class - XIIComputer networks - CBSE  New Syllabus (083) Class - XII
Computer networks - CBSE New Syllabus (083) Class - XIIDeepak Singh
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-fileDeepak Singh
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handlingDeepak Singh
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classDeepak Singh
 
Chapter26 inheritance-ii
Chapter26 inheritance-iiChapter26 inheritance-ii
Chapter26 inheritance-iiDeepak Singh
 
Chapter25 inheritance-i
Chapter25 inheritance-iChapter25 inheritance-i
Chapter25 inheritance-iDeepak Singh
 
Chapter24 operator-overloading
Chapter24 operator-overloadingChapter24 operator-overloading
Chapter24 operator-overloadingDeepak Singh
 
Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-classDeepak Singh
 
Chapter22 static-class-member-example
Chapter22 static-class-member-exampleChapter22 static-class-member-example
Chapter22 static-class-member-exampleDeepak Singh
 
Chapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-filesChapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-filesDeepak Singh
 
Chapter20 class-example-program
Chapter20 class-example-programChapter20 class-example-program
Chapter20 class-example-programDeepak Singh
 
Chapter19 constructor-and-destructor
Chapter19 constructor-and-destructorChapter19 constructor-and-destructor
Chapter19 constructor-and-destructorDeepak Singh
 
Chapter18 class-and-objects
Chapter18 class-and-objectsChapter18 class-and-objects
Chapter18 class-and-objectsDeepak Singh
 
Chapter15 structure
Chapter15 structureChapter15 structure
Chapter15 structureDeepak Singh
 
Chapter13 two-dimensional-array
Chapter13 two-dimensional-arrayChapter13 two-dimensional-array
Chapter13 two-dimensional-arrayDeepak Singh
 
Chapter12 array-single-dimension
Chapter12 array-single-dimensionChapter12 array-single-dimension
Chapter12 array-single-dimensionDeepak Singh
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 FunctionDeepak Singh
 
Chapter 10 Library Function
Chapter 10 Library FunctionChapter 10 Library Function
Chapter 10 Library FunctionDeepak Singh
 

More from Deepak Singh (20)

Computer networks - CBSE New Syllabus (083) Class - XII
Computer networks - CBSE  New Syllabus (083) Class - XIIComputer networks - CBSE  New Syllabus (083) Class - XII
Computer networks - CBSE New Syllabus (083) Class - XII
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-file
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handling
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
Chapter26 inheritance-ii
Chapter26 inheritance-iiChapter26 inheritance-ii
Chapter26 inheritance-ii
 
Chapter25 inheritance-i
Chapter25 inheritance-iChapter25 inheritance-i
Chapter25 inheritance-i
 
Chapter24 operator-overloading
Chapter24 operator-overloadingChapter24 operator-overloading
Chapter24 operator-overloading
 
Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-class
 
Chapter22 static-class-member-example
Chapter22 static-class-member-exampleChapter22 static-class-member-example
Chapter22 static-class-member-example
 
Chapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-filesChapter21 separate-header-and-implementation-files
Chapter21 separate-header-and-implementation-files
 
Chapter20 class-example-program
Chapter20 class-example-programChapter20 class-example-program
Chapter20 class-example-program
 
Chapter19 constructor-and-destructor
Chapter19 constructor-and-destructorChapter19 constructor-and-destructor
Chapter19 constructor-and-destructor
 
Chapter18 class-and-objects
Chapter18 class-and-objectsChapter18 class-and-objects
Chapter18 class-and-objects
 
Chapter17 oop
Chapter17 oopChapter17 oop
Chapter17 oop
 
Chapter16 pointer
Chapter16 pointerChapter16 pointer
Chapter16 pointer
 
Chapter15 structure
Chapter15 structureChapter15 structure
Chapter15 structure
 
Chapter13 two-dimensional-array
Chapter13 two-dimensional-arrayChapter13 two-dimensional-array
Chapter13 two-dimensional-array
 
Chapter12 array-single-dimension
Chapter12 array-single-dimensionChapter12 array-single-dimension
Chapter12 array-single-dimension
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Chapter 10 Library Function
Chapter 10 Library FunctionChapter 10 Library Function
Chapter 10 Library Function
 

Recently uploaded

Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 

Recently uploaded (20)

Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 

Chapter 3 - Variable Memory Concept

  • 1. www.cppforschool.com Variable : Memory Concept Programs shown in the previous section print text on the screen. This section will introduce the concept of variable so that our program can perform calculation on data. Program : Adding two numbers We'll solve this problem in C++ with the following steps: STEP 1 : Allocate memory for storing three numbers STEP 2 : Store first number in computer memory STEP 3 : Store second number in computer memory STEP 4 : Add these two numbers together and store the result of the addition in a third memory location STEP 5 : Print the result STEP 1 : Now first we'll allocate memory for storing numbers. Location of the computer memory which is used to store data and is given a symbolic name for reference is known as variable. We need three variables, two for storing input and third for storing result. Before a variable is used in a program, we must declare it. This activity enables the compiler to make available the appropriate type of location in the memory. Following statements declare three variables of type integer to store whole numbers. int x; int y; int z; You can declare more than one variable of same type in a single statement like : int x, y, z; STEP 2 : Following statement stores value in first variable
  • 2. x = 25; STEP 3 : Following statement stores value in second variable y = 10; STEP 4 : Now, add these two numbers together and store the result of the addition in third variable z = x + y; STEP 5 : Print the result cout << "The sum is "; cout << sum; You can combine above two statements in one statement cout << "The sum is " << sum; here, is the complete program #include <iostream> using namespace std; int main() { //declare variables of integer type int x; int y; int z; //storing value in variables x = 25; y = 10; //adding numbers and store the result in sum z = x + y; //print the result cout << "The sum is "; cout << z; return 0; } Output : The sum is 35
  • 3. Identifiers Symbolic names can be used in C++ for various data items used by a programmer in his program. A symbolic name is generally known as an identifier. The identifier is a sequence of characters taken from C++ character set. In previous program x, y and z are identifiers of variables. The rule for the formation of an identifier are:  An identifier can consist of alphabets, digits and/or underscores.  It must not start with a digit  C++ is case sensitive that is upper case and lower case letters are considered different from each other.  It should not be a reserved word. Keywords There are some reserved words in C++ which have predefined meaning to compiler called keywords. These words may not be used as identifiers. Some commonly used Keywords are given below: asm auto bool break case catch char class const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while