SlideShare a Scribd company logo
1 of 24
Prepared By: Asst. Prof. Sejal Jadav
Unit-1
Principles of Object Oriented Programming Tokens,
expressions & Control Statements
(14 MARKS)
B.C.A & B.Sc.(IT) – 3
CS-13 C++ and Object Oriented
Programming
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Explain Symbolic Constants with example.
• # define <variable_nm> <constant_value>
• Above syntax is used in C. using # define directive,
constants have no type information.
• Instead, in C++ using ‘const’ qualifier, the constants
can be defined with their data types.
Prepared By: Asst. Prof. Sejal Jadav
• Using the qualifier ‘const’
Syntax
• const <datatype> <variable_name> = <constant_value>;
Example
• const float pi = 3.14;
• Even though the datatype part is optional.
• If datatype is not specified the default datatype is
integer.
Prepared By: Asst. Prof. Sejal Jadav
Example
• const int size = 10;
• above statement is identical to const size = 10;
• C++ requires a const to be initialized immediately
when it is declared otherwise it will generate an
error.
• const int size; //error
• size = 10; //not valid
Prepared By: Asst. Prof. Sejal Jadav
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
const int size=10;
char name[size];
cout<<endl<<"enter your name: ";
cin>>name;
cout<<name;
//size=15;// error cannot modify a const object
}
Prepared By: Asst. Prof. Sejal Jadav
Defining a set of integer constants using ‘enum’ keyword.
• An enumerated data type is another user defined type
which provides a way for attaching names to
numbers.
• They are named integers.
• Can be defined much like structures.
Prepared By: Asst. Prof. Sejal Jadav
Syntax
enum [<type_tag>]
{
<constant_name> = [<value>]
…..
} [variable_list…];
• Here type tag and variable list is also optional.
Prepared By: Asst. Prof. Sejal Jadav
Example
enum color
{
red,
blue,
green=10,
yellow,
black=50,}e1,e2;
Prepared By: Asst. Prof. Sejal Jadav
• Here type tag and variable list is also optional.
• The enum keyword automatically enumerates a list of
words by assigning them values 0,1,2 and so on.
• We can also change the values by assigning words
with constant values.
• Provides an alternative way for creating symbolic
constants.
Prepared By: Asst. Prof. Sejal Jadav
enum color
{
red,
blue,
green=10,
yellow,
black=50,}
Here values are as under
red = 0
blue = 1
green = 10
yellow = 11
black = 50
Prepared By: Asst. Prof. Sejal Jadav
• when we assign green=10 then the subsequent word
yellow is automatically assigns with the value 11.
• Note that the subsequent initialized enumerators are
larger by one than their predecessors.
• Let’s see examples…….
Prepared By: Asst. Prof. Sejal Jadav
Short note on Declaration & Dynamic
initialization of variables
• Variable are used in C++, where we need storage for
any value, which will change in program.
• Variable can be declared in multiple ways each with
different memory requirements and functioning.
• Variable is the name of memory location allocated by
the compiler depending upon the datatype of the
variable.
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Declaration and Initialization
• Variable must be declared before they are used.
Usually it is preferred to declare them at the starting
of the program, but in C++ they can be declared in the
middle of program too, but must be done before using
them.
Prepared By: Asst. Prof. Sejal Jadav
For example:
• int i; // declared but not initialised
• char c;
• int i, j, k; // Multiple declaration
Prepared By: Asst. Prof. Sejal Jadav
• Initialization means assigning value to an already declared
variable,
int i; // declaration
i = 10; // initialization
• Initialization and declaration can be done in one single step
also,
int i=10; //initialization and declaration in same step
int i=10, j=11;
Prepared By: Asst. Prof. Sejal Jadav
• If a variable is declared and not initialized by default it
will hold a garbage value.
• Also, if a variable is once declared and if try to declare it
again, we will get a compile time error.
int i,j;
i=10;
j=20;
int j=i+j; //compile time error, cannot redeclare a
variable in same scope
Prepared By: Asst. Prof. Sejal Jadav
example
Prepared By: Asst. Prof. Sejal Jadav
What is Reference variable? Explain with example
• C++ introduced new kind of variable known as
reference variable.
• A reference variable provides an alias [alternative
name] for existing variable.
• Syntax
• data_type & refrence_name = variable_name
Prepared By: Asst. Prof. Sejal Jadav
Example:
float total = 100;
float &sum = total;
• Here sum is a reference to variable total.
• So sum and total can be used interchangeably to represent
that variable data.
• And therefore
cout << total; //100
cout << sum; //100
• Both the statements are identical.
Prepared By: Asst. Prof. Sejal Jadav
Consider following statements
total = total + 10;
cout << sum; //110
sum = 0;
cout << total; //0
Prepared By: Asst. Prof. Sejal Jadav
• Reference means Address.
• Reference variable is an internal pointer.
• A reference variable must be initialized at the time of
declaration.
Prepared By: Asst. Prof. Sejal Jadav
• C++ assigns additional meaning to & symbol. Here &
symbol is not the address operator but it is reference
operator
• It can be initialized with already declared variables
only.
• Reference variable cannot be updated.
Prepared By: Asst. Prof. Sejal Jadav
• Look at the following statement
char &nuln = ‘n’
• Unlike pointer, this will create reference to the
unknown location where the new line constant n is
stored.
• Let’s see example…………..

More Related Content

What's hot

Pointer and polymorphism
Pointer and polymorphismPointer and polymorphism
Pointer and polymorphismSangeethaSasi1
 
Maximum likelihood-set - introduction
Maximum likelihood-set - introductionMaximum likelihood-set - introduction
Maximum likelihood-set - introductionYusuke Matsubara
 
Compiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statementsCompiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statementsGeo Marian
 
Python recursion
Python recursionPython recursion
Python recursionToniyaP1
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersRichard Thomson
 
Akshay Sharma,BCA,2nd year
Akshay Sharma,BCA,2nd yearAkshay Sharma,BCA,2nd year
Akshay Sharma,BCA,2nd yeardezyneecole
 
Deepak Soni,BCA 2nd Year
Deepak Soni,BCA 2nd YearDeepak Soni,BCA 2nd Year
Deepak Soni,BCA 2nd Yeardezyneecole
 
The task is to convert a given integer grade (0..100) into a corresponding le...
The task is to convert a given integer grade (0..100) into a corresponding le...The task is to convert a given integer grade (0..100) into a corresponding le...
The task is to convert a given integer grade (0..100) into a corresponding le...hwbloom26
 
Pooja Sharma ,BCA 2nd Year
Pooja Sharma ,BCA 2nd YearPooja Sharma ,BCA 2nd Year
Pooja Sharma ,BCA 2nd Yeardezyneecole
 
Scala overview
Scala overviewScala overview
Scala overviewdogstar
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphismkiran Patel
 

What's hot (19)

Pointer and polymorphism
Pointer and polymorphismPointer and polymorphism
Pointer and polymorphism
 
Maximum likelihood-set - introduction
Maximum likelihood-set - introductionMaximum likelihood-set - introduction
Maximum likelihood-set - introduction
 
Compiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statementsCompiler: Programming Language= Assignments and statements
Compiler: Programming Language= Assignments and statements
 
Python recursion
Python recursionPython recursion
Python recursion
 
C traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmersC traps and pitfalls for C++ programmers
C traps and pitfalls for C++ programmers
 
Javascript ch6
Javascript ch6Javascript ch6
Javascript ch6
 
Akshay Sharma,BCA,2nd year
Akshay Sharma,BCA,2nd yearAkshay Sharma,BCA,2nd year
Akshay Sharma,BCA,2nd year
 
functions in C
functions in Cfunctions in C
functions in C
 
Deepak Soni,BCA 2nd Year
Deepak Soni,BCA 2nd YearDeepak Soni,BCA 2nd Year
Deepak Soni,BCA 2nd Year
 
The task is to convert a given integer grade (0..100) into a corresponding le...
The task is to convert a given integer grade (0..100) into a corresponding le...The task is to convert a given integer grade (0..100) into a corresponding le...
The task is to convert a given integer grade (0..100) into a corresponding le...
 
Pooja Sharma ,BCA 2nd Year
Pooja Sharma ,BCA 2nd YearPooja Sharma ,BCA 2nd Year
Pooja Sharma ,BCA 2nd Year
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
Scala overview
Scala overviewScala overview
Scala overview
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
SPL 5 | scanf in C
SPL 5 | scanf in CSPL 5 | scanf in C
SPL 5 | scanf in C
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
 
OOP - Templates
OOP - TemplatesOOP - Templates
OOP - Templates
 
Function Pointer in C
Function Pointer in CFunction Pointer in C
Function Pointer in C
 

Similar to C++ unit-1-part-8

C++ unit-1-part-9
C++ unit-1-part-9C++ unit-1-part-9
C++ unit-1-part-9Jadavsejal
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11Jadavsejal
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7Jadavsejal
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyaviratandodariya
 
JAVA in Artificial intelligent
JAVA in Artificial intelligentJAVA in Artificial intelligent
JAVA in Artificial intelligentVirat Andodariya
 
C++ unit-1-part-13
C++ unit-1-part-13C++ unit-1-part-13
C++ unit-1-part-13Jadavsejal
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Rasan Samarasinghe
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3Jadavsejal
 
Brixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBrixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBasil Bibi
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001Ralph Weber
 
c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and SelectionAhmed Nobi
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
 
chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)It Academy
 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15Jadavsejal
 

Similar to C++ unit-1-part-8 (20)

C++ unit-1-part-9
C++ unit-1-part-9C++ unit-1-part-9
C++ unit-1-part-9
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7
 
Guide to Java.pptx
Guide to Java.pptxGuide to Java.pptx
Guide to Java.pptx
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariya
 
JAVA in Artificial intelligent
JAVA in Artificial intelligentJAVA in Artificial intelligent
JAVA in Artificial intelligent
 
C++ unit-1-part-13
C++ unit-1-part-13C++ unit-1-part-13
C++ unit-1-part-13
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3
 
Brixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBrixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 Recap
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and Selection
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)
 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15
 

More from Jadavsejal

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassJadavsejal
 
Programming Java Concept of Event Handling
Programming Java Concept of Event HandlingProgramming Java Concept of Event Handling
Programming Java Concept of Event HandlingJadavsejal
 
Programming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingProgramming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingJadavsejal
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout ManagersJadavsejal
 
C++ unit-2-part-2
C++ unit-2-part-2C++ unit-2-part-2
C++ unit-2-part-2Jadavsejal
 
C++ unit-2-part-1
C++ unit-2-part-1C++ unit-2-part-1
C++ unit-2-part-1Jadavsejal
 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14Jadavsejal
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10Jadavsejal
 
C++ unit-1-part-6
C++ unit-1-part-6C++ unit-1-part-6
C++ unit-1-part-6Jadavsejal
 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5Jadavsejal
 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4Jadavsejal
 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2Jadavsejal
 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1Jadavsejal
 
05_system architecture
05_system architecture05_system architecture
05_system architectureJadavsejal
 
04 data flow architecture
04 data flow architecture 04 data flow architecture
04 data flow architecture Jadavsejal
 
04 authentication
04 authentication04 authentication
04 authenticationJadavsejal
 

More from Jadavsejal (20)

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone Class
 
Programming Java Concept of Event Handling
Programming Java Concept of Event HandlingProgramming Java Concept of Event Handling
Programming Java Concept of Event Handling
 
Programming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event HandlingProgramming Java GUI using SWING, Event Handling
Programming Java GUI using SWING, Event Handling
 
concept of applet and concept of Layout Managers
concept of applet and concept of Layout Managersconcept of applet and concept of Layout Managers
concept of applet and concept of Layout Managers
 
C++ unit-2-part-2
C++ unit-2-part-2C++ unit-2-part-2
C++ unit-2-part-2
 
C++ unit-2-part-1
C++ unit-2-part-1C++ unit-2-part-1
C++ unit-2-part-1
 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10
 
C++ unit-1-part-6
C++ unit-1-part-6C++ unit-1-part-6
C++ unit-1-part-6
 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5
 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4
 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2
 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1
 
05_system architecture
05_system architecture05_system architecture
05_system architecture
 
04 data flow architecture
04 data flow architecture 04 data flow architecture
04 data flow architecture
 
Vpn protocols
Vpn protocolsVpn protocols
Vpn protocols
 
04 authentication
04 authentication04 authentication
04 authentication
 
03 cia
03 cia03 cia
03 cia
 
01
01 01
01
 
4 ipv6
4 ipv64 ipv6
4 ipv6
 

Recently uploaded

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 

Recently uploaded (20)

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

C++ unit-1-part-8

  • 1. Prepared By: Asst. Prof. Sejal Jadav Unit-1 Principles of Object Oriented Programming Tokens, expressions & Control Statements (14 MARKS) B.C.A & B.Sc.(IT) – 3 CS-13 C++ and Object Oriented Programming Prepared By: Asst. Prof. Sejal Jadav
  • 2. Prepared By: Asst. Prof. Sejal Jadav Explain Symbolic Constants with example. • # define <variable_nm> <constant_value> • Above syntax is used in C. using # define directive, constants have no type information. • Instead, in C++ using ‘const’ qualifier, the constants can be defined with their data types.
  • 3. Prepared By: Asst. Prof. Sejal Jadav • Using the qualifier ‘const’ Syntax • const <datatype> <variable_name> = <constant_value>; Example • const float pi = 3.14; • Even though the datatype part is optional. • If datatype is not specified the default datatype is integer.
  • 4. Prepared By: Asst. Prof. Sejal Jadav Example • const int size = 10; • above statement is identical to const size = 10; • C++ requires a const to be initialized immediately when it is declared otherwise it will generate an error. • const int size; //error • size = 10; //not valid
  • 5. Prepared By: Asst. Prof. Sejal Jadav #include<iostream> #include<conio.h> using namespace std; int main() { const int size=10; char name[size]; cout<<endl<<"enter your name: "; cin>>name; cout<<name; //size=15;// error cannot modify a const object }
  • 6. Prepared By: Asst. Prof. Sejal Jadav Defining a set of integer constants using ‘enum’ keyword. • An enumerated data type is another user defined type which provides a way for attaching names to numbers. • They are named integers. • Can be defined much like structures.
  • 7. Prepared By: Asst. Prof. Sejal Jadav Syntax enum [<type_tag>] { <constant_name> = [<value>] ….. } [variable_list…]; • Here type tag and variable list is also optional.
  • 8. Prepared By: Asst. Prof. Sejal Jadav Example enum color { red, blue, green=10, yellow, black=50,}e1,e2;
  • 9. Prepared By: Asst. Prof. Sejal Jadav • Here type tag and variable list is also optional. • The enum keyword automatically enumerates a list of words by assigning them values 0,1,2 and so on. • We can also change the values by assigning words with constant values. • Provides an alternative way for creating symbolic constants.
  • 10. Prepared By: Asst. Prof. Sejal Jadav enum color { red, blue, green=10, yellow, black=50,} Here values are as under red = 0 blue = 1 green = 10 yellow = 11 black = 50
  • 11. Prepared By: Asst. Prof. Sejal Jadav • when we assign green=10 then the subsequent word yellow is automatically assigns with the value 11. • Note that the subsequent initialized enumerators are larger by one than their predecessors. • Let’s see examples…….
  • 12. Prepared By: Asst. Prof. Sejal Jadav Short note on Declaration & Dynamic initialization of variables • Variable are used in C++, where we need storage for any value, which will change in program. • Variable can be declared in multiple ways each with different memory requirements and functioning. • Variable is the name of memory location allocated by the compiler depending upon the datatype of the variable.
  • 13. Prepared By: Asst. Prof. Sejal Jadav
  • 14. Prepared By: Asst. Prof. Sejal Jadav Declaration and Initialization • Variable must be declared before they are used. Usually it is preferred to declare them at the starting of the program, but in C++ they can be declared in the middle of program too, but must be done before using them.
  • 15. Prepared By: Asst. Prof. Sejal Jadav For example: • int i; // declared but not initialised • char c; • int i, j, k; // Multiple declaration
  • 16. Prepared By: Asst. Prof. Sejal Jadav • Initialization means assigning value to an already declared variable, int i; // declaration i = 10; // initialization • Initialization and declaration can be done in one single step also, int i=10; //initialization and declaration in same step int i=10, j=11;
  • 17. Prepared By: Asst. Prof. Sejal Jadav • If a variable is declared and not initialized by default it will hold a garbage value. • Also, if a variable is once declared and if try to declare it again, we will get a compile time error. int i,j; i=10; j=20; int j=i+j; //compile time error, cannot redeclare a variable in same scope
  • 18. Prepared By: Asst. Prof. Sejal Jadav example
  • 19. Prepared By: Asst. Prof. Sejal Jadav What is Reference variable? Explain with example • C++ introduced new kind of variable known as reference variable. • A reference variable provides an alias [alternative name] for existing variable. • Syntax • data_type & refrence_name = variable_name
  • 20. Prepared By: Asst. Prof. Sejal Jadav Example: float total = 100; float &sum = total; • Here sum is a reference to variable total. • So sum and total can be used interchangeably to represent that variable data. • And therefore cout << total; //100 cout << sum; //100 • Both the statements are identical.
  • 21. Prepared By: Asst. Prof. Sejal Jadav Consider following statements total = total + 10; cout << sum; //110 sum = 0; cout << total; //0
  • 22. Prepared By: Asst. Prof. Sejal Jadav • Reference means Address. • Reference variable is an internal pointer. • A reference variable must be initialized at the time of declaration.
  • 23. Prepared By: Asst. Prof. Sejal Jadav • C++ assigns additional meaning to & symbol. Here & symbol is not the address operator but it is reference operator • It can be initialized with already declared variables only. • Reference variable cannot be updated.
  • 24. Prepared By: Asst. Prof. Sejal Jadav • Look at the following statement char &nuln = ‘n’ • Unlike pointer, this will create reference to the unknown location where the new line constant n is stored. • Let’s see example…………..