SlideShare a Scribd company logo
OPERATORS IN C++
 C++ has a rich set of operator which
include C operators.
 In addition to this some new operator are
included.
 Operators are:
 Insertion operator <<
 Extraction operator >>
 Scope resolution operator ::
 Pointer-to-member ::*
 Pointer-to-member ->*
 Pointer-to-member operator .*
 Memory release operator delete
 Line feed operator endl
 Memory allocation operator new
 Field width operator setw
SCOPE RESOLUTION OPERATOR
 C++ is block-structured language like C.
 The same variable name can be used to
different meaning in different block.
 The scope of the variable is within the block.
 A variable declared inside a block is said to
be local to the block.
TWO DIFFERENT MEMORY LOCATIONS NESTED OF BLOCKS
……………
……………
{
int x=10;
……………
……………
}
……………
……………
{
int x=1;
……………
……………
}
……………
……………
{
int x=10;
……………
……………
{
int x=1;
……………
……………
}
……………
}
 In C, the global version of a variable
cannot be accessed from within the inner
block.
 C++ resolves this problem by introducing
a new operator :: called scope resolution
operator.
 Usage: To uncover a hidden variable
 Syntax: :: variable name
 It allows access to the global version of a
variable.
PROGRAM FOR SCOPE RESOLUTION
OPERATOR#include <iostream>
using namespace std;
int m=10;
int main()
{
int m=20;
{
int k=m;
int m=30;
cout<<“We are in inner blockn”;
cout<<“k=“<<k<<“n”;
cout<<“m=“<<m<<“n”;
cout<<“::m=“<<::m<<“n”;
}
cout<<“n We are in outer block n”;
cout<<“m=“<<m<<“n”;
cout<<“::m=“<<::m<<“n”;
return 0;
}
 Output:
We are in inner block
k=20
m=30
::m=10
We are in outer block
m=20
::m=10
MEMBER DEREFERENCING OPERATOR
 C++ permits us to define a class
containing various types of data and
function as members.
 C++ permits us to access the class
members through pointers. In order to
achieve three pointer-to-member
operators.operators function
::* To declare a pointer to a member of a class
* To access a member using object name and a pointer to that
member
->* To access a member using a pointer to the object and a pointer
to that member.
MEMORY MANAGEMENT SYSTEM
 C uses malloc() and calloc() functions to
allocate memory dynamically at run time and
free() functionally to free dynamically
allocated memory .
 Although C++ these two functions, it also
defines two unary operators new and delete
that perform the task of allocating and freeing
the memories in better and easier way.
 An object can be created and will remain
existence until it is explicitly destroyed by
using delete.
 Thus, the lifetime of an object is directly
under our control and is unrelated to the
block structure of the program.
 General format for New operator:
Pointer-variable =new data type;
 Here, pointer variable is a pointer of
type-data type. The new operator
allocates sufficient memory to hold a
data-type. The pointer variable holds the
address of the memory space allocated.
 Examples:
p=new int;  int *p=new int;
We can initialize the memory using new
operator by pointer-variable = new data-
type(value/size);
Example: int *p=new int(25);
array-ptr= new int [3][4][5];
 Delete is used to destroy release
the memory space for reuse.
 General form
delete pointer-variable;
 To delete a dynamically allocated
array
delete [size] pointer-variable;
 The new operator offers the following
advantages
 It automatically computes the compute the size
of the data object.
 It automatically returns the correct pointer type,
so that there is no need to use a type cast.
 It is possible to initialize the object while creating
the memory space.
MANIPULATIONS
 Manipulations are operators that are used to
format the data display. The most commonly
used manipulators are endl and setw.
 The endl manipulator when used in output
statement, causes a linefeed to be inserted.
 It has the same effect as using the newline.
 If we assume the values of the variable as
2597, 14 and 175 respectively, the output will
appear as shown below:
 m=
 n=
 p=
2 5 9 7
1 4
1 7 5
 Numbers are right justified to get this the
O/P we should specify the common field
width for all the numbers and force them to
print like the below example:
 Example:
 m= 2597
 n= 14
 p= 157
 Its format is cout<< setw(5)<<sum<<endl;
 O/P: 2 5 9 7
USE OF MANIPULATIONS
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int basic=950,allowance=95,total=1045;
cout<<setw(10)<<“Basic”<<
setw(10)<<basic<<endl;
cout<<setw(10)<<“Allowance”<<
setw(10)<<allowance<<endl;
cout<<setw(10)<<“Total”<<
setw(10)<<total<<endl;
return0;
OUTPUT
9 5 0basic
9 5allowance
Total
1 0 4 5
TYPE CAST OPERATOR
 C++ permits explicit type conversion of
variable or expression using the type cast
operator.
 Examples:
 ANSI C++ adds the following new cast
operators:
 const_cast
 static_cast
 dynamic_cast
Traditional C ANSI C++
(type-name) expression type-name(expression)
Traditional C ANSI C++
average=sum/(float)i; average=sum/float(i);
EXPRESSION AND THEIR TYPES
 An expression is a combination of
operators, constants and variable. It may
include functions call which consist of one
or more operands.
 Types of expression:
 Constant expression
 Integral expression
 Float expression
 Pointer expression
 Relational expression
 Logical expression
 Bitwise expression
TYPES OF EXPRESSION
 Constant expression consist of only constant
expression.
 Ex: 15+5/20;
 Integral expression are those which produce integer
results after implementing all the automatic and explicit
 Ex: x+y
 Pointer expression produce address values.
 Ex:&m, ptr. Here m is a variable and per is a pointer.
 Relational expression yield a result of type bool which
takes a value true or false.
 Example
x<=y
Relational expressions are also known as Boolean
expression.
 Logical expressions combine two or more
relational expressions and produces bool
type results.
 Examples :A>b x==10
 Bitwise expression are used to
manipulate data at bit level. They are
basically used for testing or shifting bits.
 Example x<<3 //shift three bit to left
Y>> 1 // shift tree bit to right
SPECIAL ASSIGNMENT EXPRESSION
 Chained assignment: A chained statement
be used to initialise variable at the time of
declaration instances, the statement
float a=b=12.34; wrong
float a=12.34, b=12.34correct.
 Embedded assignment:
x=(y=50)+10;y=50;x=y+10;
Here y=50 is an embedded assignment.
Here, the value 50 is assigned to y and
then result 50+10=60 is assigned to x.
IMPLICIT CONVERSION
 M=5+2.75; is a valid statement . Wherever
data type are mixed in an expression, C++
performs conversion automatically . This is
called as implicit conversion or automatic
conversion.
WATER-FALL MODEL
int
unsigned
long int
Unsigned long int
float
double
long double
int
char
RESULT OF MIXED-MODE OPERATOR
Rho
Lho
char Short Int Long float Double Long double
char Int Int Int Long float Double Long double
Short Int Int Int Long float Double Long double
Int Int Int Int Long float Double Long double
Long Long Long Long Long float Double Long double
float float float float float float Double Long double
Double Double Double Double Double Double Double Long double
Long
double
Long
double
Long
double
Long
double
Long
double
Long
double
Long
double
Long double
OPERATOR OVERLOADING
 Overloading means assigning different
meanings to an operation.
 The operator * when applied to pointer
variable gives the value pointed to the
pointer. It is commonly used for multiplying
two numbers.
OPERATOR PRECEDENCE
 C++ enables us to add multiple meaning to
the operators, yet their association and
precedence remain the same.
 For example the multiplication operator will
continue having higher precedence than the
add operator.
OPERATOR PRECEDENCE AND ASSOCIATIVITY
CONTROL STRUCTURES
 A function is set up to perform a task. When the
task is complex, many different algorithm can be
achieved to perform the goal.
 Some of them may be complex to comprehend,
while others are not.
 Experience has also shown that the number of
bugs that occur is related to the format of the
program.
 The format should be such that is easy to trace
the flow of execution of the program later.
 This would help not only in debugging but also
in the review an maintainable of the program
later.
 There are three
control structure :
 Sequence control
 Selection
structure
 Loop structure
SWITCH STATEMENT
This is a multiple-branching statement where , based
on a condition , the control transferred to many
possible points.
FOR STATEMENT
The for loop is entry checked loop and is used when
an action is to be repeated for a predetermined
number of times.
WHILE STATEMENT
while(condition)
{
action1;
}
Action2;
It is a entry-controlled loop.
DO-WHILE STATEMENT
It is an exit-controlled loop. Based on a condition, the
control is transferred back to a particular point in the
program.
Operators

More Related Content

What's hot

Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
Dharma Kshetri
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
NabeelaNousheen
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
VC Infotech
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
Jasleen Kaur (Chandigarh University)
 
C++ Language
C++ LanguageC++ Language
C++ Language
Syed Zaid Irshad
 
functions in C
functions in Cfunctions in C
functions in C
Mehwish Mehmood
 
Function overloading
Function overloadingFunction overloading
Function overloading
Sudeshna Biswas
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
Syed Mustafa
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
HNDE Labuduwa Galle
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
Faisal Shahzad Khan
 
Functions in C
Functions in CFunctions in C
Functions in C
Princy Nelson
 
M11 operator overloading and type conversion
M11 operator overloading and type conversionM11 operator overloading and type conversion
M11 operator overloading and type conversion
NabeelaNousheen
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
 
Types of function call
Types of function callTypes of function call
Types of function call
ArijitDhali
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
harman kaur
 

What's hot (20)

Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Chap 9(functions)
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
functions in C
functions in Cfunctions in C
functions in C
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
 
Pointers
PointersPointers
Pointers
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
Functions in C
Functions in CFunctions in C
Functions in C
 
M11 operator overloading and type conversion
M11 operator overloading and type conversionM11 operator overloading and type conversion
M11 operator overloading and type conversion
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Functions
FunctionsFunctions
Functions
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 

Viewers also liked

Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
Jasleen Kaur (Chandigarh University)
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
Mohammed Saleh
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Deepak Singh
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
Stoian Kirov
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
Praveen M Jigajinni
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
Online
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++Pranav Ghildiyal
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
rajveer_Pannu
 
New operator and methods.15
New operator and methods.15New operator and methods.15
New operator and methods.15myrajendra
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
Himanshu Kaushik
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
archikabhatia
 
Template at c++
Template at c++Template at c++
Template at c++
Lusain Kim
 
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
gourav kottawar
 

Viewers also liked (20)

Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Matrices
MatricesMatrices
Matrices
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
New operator and methods.15
New operator and methods.15New operator and methods.15
New operator and methods.15
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
 
Template at c++
Template at c++Template at c++
Template at c++
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Managing console
Managing consoleManaging console
Managing console
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
 

Similar to Operators

C operators
C operatorsC operators
C operators
GPERI
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operatorSAFFI Ud Din Ahmad
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
Sabi995708
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 
ForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptx
AaliyanShaikh
 
Ch-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfCh-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdf
esuEthopi
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
WondimuBantihun1
 
Pseudocode
PseudocodePseudocode
Pseudocode
Harsha Madushanka
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
Mohammed Saleh
 
additional.pptx
additional.pptxadditional.pptx
additional.pptx
Yuvraj994432
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
Warui Maina
 
C programming language
C programming languageC programming language
C programming language
Abin Rimal
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Dushmanta Nath
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
LidetAdmassu
 

Similar to Operators (20)

C operators
C operatorsC operators
C operators
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
C fundamental
C fundamentalC fundamental
C fundamental
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
ForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptx
 
Ch-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdfCh-4-Operator Overloading.pdf
Ch-4-Operator Overloading.pdf
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Chap 3 c++
Chap 3 c++Chap 3 c++
Chap 3 c++
 
What is c
What is cWhat is c
What is c
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
additional.pptx
additional.pptxadditional.pptx
additional.pptx
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
C programming language
C programming languageC programming language
C programming language
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
3d7b7 session4 c++
3d7b7 session4 c++3d7b7 session4 c++
3d7b7 session4 c++
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
 

Operators

  • 1.
  • 2. OPERATORS IN C++  C++ has a rich set of operator which include C operators.  In addition to this some new operator are included.  Operators are:  Insertion operator <<  Extraction operator >>  Scope resolution operator ::  Pointer-to-member ::*  Pointer-to-member ->*
  • 3.  Pointer-to-member operator .*  Memory release operator delete  Line feed operator endl  Memory allocation operator new  Field width operator setw
  • 4. SCOPE RESOLUTION OPERATOR  C++ is block-structured language like C.  The same variable name can be used to different meaning in different block.  The scope of the variable is within the block.  A variable declared inside a block is said to be local to the block.
  • 5. TWO DIFFERENT MEMORY LOCATIONS NESTED OF BLOCKS …………… …………… { int x=10; …………… …………… } …………… …………… { int x=1; …………… …………… } …………… …………… { int x=10; …………… …………… { int x=1; …………… …………… } …………… }
  • 6.  In C, the global version of a variable cannot be accessed from within the inner block.  C++ resolves this problem by introducing a new operator :: called scope resolution operator.  Usage: To uncover a hidden variable  Syntax: :: variable name  It allows access to the global version of a variable.
  • 7. PROGRAM FOR SCOPE RESOLUTION OPERATOR#include <iostream> using namespace std; int m=10; int main() { int m=20; { int k=m; int m=30; cout<<“We are in inner blockn”; cout<<“k=“<<k<<“n”; cout<<“m=“<<m<<“n”; cout<<“::m=“<<::m<<“n”; } cout<<“n We are in outer block n”; cout<<“m=“<<m<<“n”; cout<<“::m=“<<::m<<“n”; return 0; }
  • 8.  Output: We are in inner block k=20 m=30 ::m=10 We are in outer block m=20 ::m=10
  • 9. MEMBER DEREFERENCING OPERATOR  C++ permits us to define a class containing various types of data and function as members.  C++ permits us to access the class members through pointers. In order to achieve three pointer-to-member operators.operators function ::* To declare a pointer to a member of a class * To access a member using object name and a pointer to that member ->* To access a member using a pointer to the object and a pointer to that member.
  • 10. MEMORY MANAGEMENT SYSTEM  C uses malloc() and calloc() functions to allocate memory dynamically at run time and free() functionally to free dynamically allocated memory .  Although C++ these two functions, it also defines two unary operators new and delete that perform the task of allocating and freeing the memories in better and easier way.
  • 11.  An object can be created and will remain existence until it is explicitly destroyed by using delete.  Thus, the lifetime of an object is directly under our control and is unrelated to the block structure of the program.  General format for New operator: Pointer-variable =new data type;
  • 12.  Here, pointer variable is a pointer of type-data type. The new operator allocates sufficient memory to hold a data-type. The pointer variable holds the address of the memory space allocated.  Examples: p=new int;  int *p=new int; We can initialize the memory using new operator by pointer-variable = new data- type(value/size); Example: int *p=new int(25); array-ptr= new int [3][4][5];
  • 13.  Delete is used to destroy release the memory space for reuse.  General form delete pointer-variable;  To delete a dynamically allocated array delete [size] pointer-variable;
  • 14.  The new operator offers the following advantages  It automatically computes the compute the size of the data object.  It automatically returns the correct pointer type, so that there is no need to use a type cast.  It is possible to initialize the object while creating the memory space.
  • 15. MANIPULATIONS  Manipulations are operators that are used to format the data display. The most commonly used manipulators are endl and setw.  The endl manipulator when used in output statement, causes a linefeed to be inserted.  It has the same effect as using the newline.
  • 16.  If we assume the values of the variable as 2597, 14 and 175 respectively, the output will appear as shown below:  m=  n=  p= 2 5 9 7 1 4 1 7 5
  • 17.  Numbers are right justified to get this the O/P we should specify the common field width for all the numbers and force them to print like the below example:  Example:  m= 2597  n= 14  p= 157  Its format is cout<< setw(5)<<sum<<endl;  O/P: 2 5 9 7
  • 18. USE OF MANIPULATIONS #include<iostream> #include<conio.h> using namespace std; int main() { int basic=950,allowance=95,total=1045; cout<<setw(10)<<“Basic”<< setw(10)<<basic<<endl; cout<<setw(10)<<“Allowance”<< setw(10)<<allowance<<endl; cout<<setw(10)<<“Total”<< setw(10)<<total<<endl; return0;
  • 19. OUTPUT 9 5 0basic 9 5allowance Total 1 0 4 5
  • 20. TYPE CAST OPERATOR  C++ permits explicit type conversion of variable or expression using the type cast operator.  Examples:  ANSI C++ adds the following new cast operators:  const_cast  static_cast  dynamic_cast Traditional C ANSI C++ (type-name) expression type-name(expression) Traditional C ANSI C++ average=sum/(float)i; average=sum/float(i);
  • 21. EXPRESSION AND THEIR TYPES  An expression is a combination of operators, constants and variable. It may include functions call which consist of one or more operands.  Types of expression:  Constant expression  Integral expression  Float expression  Pointer expression  Relational expression  Logical expression  Bitwise expression
  • 22. TYPES OF EXPRESSION  Constant expression consist of only constant expression.  Ex: 15+5/20;  Integral expression are those which produce integer results after implementing all the automatic and explicit  Ex: x+y  Pointer expression produce address values.  Ex:&m, ptr. Here m is a variable and per is a pointer.  Relational expression yield a result of type bool which takes a value true or false.  Example x<=y Relational expressions are also known as Boolean expression.
  • 23.  Logical expressions combine two or more relational expressions and produces bool type results.  Examples :A>b x==10  Bitwise expression are used to manipulate data at bit level. They are basically used for testing or shifting bits.  Example x<<3 //shift three bit to left Y>> 1 // shift tree bit to right
  • 24. SPECIAL ASSIGNMENT EXPRESSION  Chained assignment: A chained statement be used to initialise variable at the time of declaration instances, the statement float a=b=12.34; wrong float a=12.34, b=12.34correct.  Embedded assignment: x=(y=50)+10;y=50;x=y+10; Here y=50 is an embedded assignment. Here, the value 50 is assigned to y and then result 50+10=60 is assigned to x.
  • 25. IMPLICIT CONVERSION  M=5+2.75; is a valid statement . Wherever data type are mixed in an expression, C++ performs conversion automatically . This is called as implicit conversion or automatic conversion.
  • 26. WATER-FALL MODEL int unsigned long int Unsigned long int float double long double int char
  • 27. RESULT OF MIXED-MODE OPERATOR Rho Lho char Short Int Long float Double Long double char Int Int Int Long float Double Long double Short Int Int Int Long float Double Long double Int Int Int Int Long float Double Long double Long Long Long Long Long float Double Long double float float float float float float Double Long double Double Double Double Double Double Double Double Long double Long double Long double Long double Long double Long double Long double Long double Long double
  • 28. OPERATOR OVERLOADING  Overloading means assigning different meanings to an operation.  The operator * when applied to pointer variable gives the value pointed to the pointer. It is commonly used for multiplying two numbers.
  • 29. OPERATOR PRECEDENCE  C++ enables us to add multiple meaning to the operators, yet their association and precedence remain the same.  For example the multiplication operator will continue having higher precedence than the add operator.
  • 30. OPERATOR PRECEDENCE AND ASSOCIATIVITY
  • 31. CONTROL STRUCTURES  A function is set up to perform a task. When the task is complex, many different algorithm can be achieved to perform the goal.  Some of them may be complex to comprehend, while others are not.  Experience has also shown that the number of bugs that occur is related to the format of the program.  The format should be such that is easy to trace the flow of execution of the program later.  This would help not only in debugging but also in the review an maintainable of the program later.
  • 32.  There are three control structure :  Sequence control  Selection structure  Loop structure
  • 33.
  • 34. SWITCH STATEMENT This is a multiple-branching statement where , based on a condition , the control transferred to many possible points.
  • 35. FOR STATEMENT The for loop is entry checked loop and is used when an action is to be repeated for a predetermined number of times.
  • 37. DO-WHILE STATEMENT It is an exit-controlled loop. Based on a condition, the control is transferred back to a particular point in the program.