SlideShare a Scribd company logo
1 of 13
FUNCTIONS
• Function is the building block of C++.
• Used to reduce the size of the program by
calling and using them in different places in
the program.
• main()Function returns an integer value.
int main();
int main(int arg);
 Function return a value using return statement.
FUNCTION PROTOTYPE
• The function interface to the compiler by
giving the details like number, data type,
arguments – function prototype.
• It is a declaration statement in calling program
type function name (argument list);
Eg:
float volume (int x, float y, z);
float volume (int, float, float);
CALL BY REFERENCE
• C++ permits to pass the parameters to the
functions by reference variable.
• When it is passed the formal argument act as
the actual argument in the calling function
void swap(int a, int b)
{
int t = a;
a = b;
b = t;
}
INLINE & RECURSION FUNCTION
• An inline function is a function that is expanded in
line when it is invoked.
• The compiler replaces the function call with the
corresponding function code.
inline function header
{
function body
}
• It send a request not a command
• Recursion means function call by itself ie one of the
statement in the function definition makes a call to
the same in which it is present.
CLASS
• Collection of objects – CLASS
• The entire set of data and code of an object can
be made a user defined data type by using
class.
• 2 Parts:
– Class Declaration – describe the type & scope of
its members
– Class function definitions – how the class
function are implemented.
• General format:
class class-name
{
private:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;
};
Class item
{
int number;
float cost;
public:
void getdata(int a, float b);
void putdata(void);
};
• Class member – the class body contains the
declaration of variables and functions.
• Data member – variables declared inside the
class.
• Member function – the function declared
inside the class.
DEFINING MEMBER FUNCTIONS
• Done by 2 ways
1. Outside the class definition
2. Inside the class definition
Outside the class definition
• Member function declared inside the class has to be
defined separately outside the class.
return-type class-name :: function-name
(argument declaration)
{
function body;
}
void item :: getdata (int a , float b)
{
number = a;
cost = b;
}
void item :: putdata (void)
{
cout<< “Number : “ << number;
cout << “Cost : “ << cost;
}
Inside the class definition
• It is to replace the function declaration by the actual
function definition inside the class.
class item
{
int number;
float cost;
public:
void getdata(int a, float b);
void putdata(void)
{
cout << number;
cout << cost;
}
};
Functions, classes & objects in c++

More Related Content

What's hot

What's hot (20)

4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Class or Object
Class or ObjectClass or Object
Class or Object
 
Object and class
Object and classObject and class
Object and class
 
C++ classes
C++ classesC++ classes
C++ classes
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Introduction to c ++ part -2
Introduction to c ++   part -2Introduction to c ++   part -2
Introduction to c ++ part -2
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
OOP C++
OOP C++OOP C++
OOP C++
 
class and objects
class and objectsclass and objects
class and objects
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
 
Learn Concept of Class and Object in C# Part 3
Learn Concept of Class and Object in C#  Part 3Learn Concept of Class and Object in C#  Part 3
Learn Concept of Class and Object in C# Part 3
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Classes and objects till 16 aug
Classes and objects till 16 augClasses and objects till 16 aug
Classes and objects till 16 aug
 
ccc
cccccc
ccc
 

Similar to Functions, classes & objects in c++

Similar to Functions, classes & objects in c++ (20)

Function class in c++
Function class in c++Function class in c++
Function class in c++
 
Function different types of funtion
Function different types of funtionFunction different types of funtion
Function different types of funtion
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Functions
FunctionsFunctions
Functions
 
Functions in c
Functions in cFunctions in c
Functions in c
 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptxUNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptx
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
Functions
FunctionsFunctions
Functions
 
1.6 Function.pdf
1.6 Function.pdf1.6 Function.pdf
1.6 Function.pdf
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 

More from ThamizhselviKrishnam (11)

Standard template library
Standard template libraryStandard template library
Standard template library
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Operators and expression in c++
Operators and  expression in c++Operators and  expression in c++
Operators and expression in c++
 
Page maker - working with text
Page maker - working with textPage maker - working with text
Page maker - working with text
 
Microprocessor & architecture
Microprocessor & architectureMicroprocessor & architecture
Microprocessor & architecture
 
Instruction set of 8085
Instruction set of 8085Instruction set of 8085
Instruction set of 8085
 
Memory and storage devices
Memory and storage devicesMemory and storage devices
Memory and storage devices
 
Generations of computer
Generations of computerGenerations of computer
Generations of computer
 
Adobe Pagemaker 7.0
Adobe Pagemaker 7.0Adobe Pagemaker 7.0
Adobe Pagemaker 7.0
 
classification of digital computer
classification of digital computerclassification of digital computer
classification of digital computer
 
Pagemaker
PagemakerPagemaker
Pagemaker
 

Recently uploaded

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

Functions, classes & objects in c++

  • 1.
  • 2. FUNCTIONS • Function is the building block of C++. • Used to reduce the size of the program by calling and using them in different places in the program. • main()Function returns an integer value. int main(); int main(int arg);  Function return a value using return statement.
  • 3. FUNCTION PROTOTYPE • The function interface to the compiler by giving the details like number, data type, arguments – function prototype. • It is a declaration statement in calling program type function name (argument list); Eg: float volume (int x, float y, z); float volume (int, float, float);
  • 4. CALL BY REFERENCE • C++ permits to pass the parameters to the functions by reference variable. • When it is passed the formal argument act as the actual argument in the calling function void swap(int a, int b) { int t = a; a = b; b = t; }
  • 5. INLINE & RECURSION FUNCTION • An inline function is a function that is expanded in line when it is invoked. • The compiler replaces the function call with the corresponding function code. inline function header { function body } • It send a request not a command • Recursion means function call by itself ie one of the statement in the function definition makes a call to the same in which it is present.
  • 6. CLASS • Collection of objects – CLASS • The entire set of data and code of an object can be made a user defined data type by using class. • 2 Parts: – Class Declaration – describe the type & scope of its members – Class function definitions – how the class function are implemented.
  • 7. • General format: class class-name { private: variable declaration; function declaration; public: variable declaration; function declaration; }; Class item { int number; float cost; public: void getdata(int a, float b); void putdata(void); };
  • 8. • Class member – the class body contains the declaration of variables and functions. • Data member – variables declared inside the class. • Member function – the function declared inside the class.
  • 9. DEFINING MEMBER FUNCTIONS • Done by 2 ways 1. Outside the class definition 2. Inside the class definition
  • 10. Outside the class definition • Member function declared inside the class has to be defined separately outside the class. return-type class-name :: function-name (argument declaration) { function body; }
  • 11. void item :: getdata (int a , float b) { number = a; cost = b; } void item :: putdata (void) { cout<< “Number : “ << number; cout << “Cost : “ << cost; }
  • 12. Inside the class definition • It is to replace the function declaration by the actual function definition inside the class. class item { int number; float cost; public: void getdata(int a, float b); void putdata(void) { cout << number; cout << cost; } };