SlideShare a Scribd company logo
Lec-07
Function,Class
Inline Function
Inline functions are functions where the call is made to
inline functions. The actual code then gets placed in the
calling program.
Once you define an inline function, using the 'inline'
keyword, whenever you call that function the compiler
will replace the function call with the actual code from
the function.
General form
inline datatype function_name(arguments)
Inline Function
#include <iostream>
using namespace std;
int func(int);
void main( )
{
int x;
cout << "n Enter the Input Value: ";
cin>>x;
cout << "n The Output is: " << func(x);
}
inline int func(int x1)
{
return 5*x1;
}
Note:-Inline functions will save time and are useful if the function is
very small. If the function is large, use of inline functions must be
avoided.
Function Overloading
• Using same function name for different purposes is
called function overloading.
• Function will perform different operations depending
on the argument list in the function call
Ex. int add(int ,int)
int add(int , float)
int add(float ,int)
int add(int ,int,int)

• A function is executed when the function call matches
the prototype with same number and type of
argument.
Function Overloading
• Function selection involves the following steps..
1. Tries to finds the exact match in which types of actual
argument are same.
2. If actual match is not found then compiler uses the
type coercion :promotion to find the match.
3. if conversion is possible to have multiple matches
then compiler will generate the error.
Ex . long sqr(long n)
double sqr(double n)
Function call
sqr(10) cause the error.
C structure revisited
• Provides a method to packing together data of
different type.
Ex struct complex
{
int real;
int img;
};
struct complex c1,c2;
Limitation of c structure:
1. c3=c1+c2 //illegal
2. Data hiding
C++ structure
• C++ supports all the features of the structures as
defined in c.
• C++ structure can have both function and data.
• Support data hiding(by defining members as private).
• Default members are public .
Class
• A class is a user defined data type
• General form of class declaration
class class_name {
private:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;

};
Class
• function and variable collectively called class
members.
• Variables declared inside the class is known as data
member and function declared inside the class is
known as member function.
• Only the member function can have access to the
private data member and private member function.
• Default members are private.
Class declaration
• Class declaration:class item{
int number; //variable declaration
float price;
public:
void getdata(int ,float); //function declaration
void putdata(void);
};
Defining member function
• Member function can be defined in two places
1. Outside the class definition.
2. Inside the class definition
Outside the class definition
• Genral form :Return_type class_name::function_name(parameter list)
{
function body;
}
Ex . void item :: getdata(int x,float y)
{
number=x;
price=y;
}
Inside the class definition
• Genral form :Return_type function_name(parameter list)
{
function body;
}
Ex . void getdata(int x,float y)
{
number=x;
price=y;
}
Accessing members of a class
• Accessing data members
object_name.datamember;
• Accessing member function
object_name.function(actual parameters);
item m;
m.getdata(5,6.5)
Note : Members are called by using their name only
inside the member function.
Private Member Function
• A private member function can only be called by another
function that is member of its class even an object can not
invoke the private function of a class using the dot operator.
Class sample {
int main()
int m;
{
void read(void)
sample s1;
public:
s1.read(); //error
void update(void);
s1.update();
};
}
void sample :: update(void)
{
read(); //simple call no object is used
}
Ad

Recommended

Functions in c++
Functions in c++
Rokonuzzaman Rony
 
Functions in c++
Functions in c++
Maaz Hasan
 
16717 functions in C++
16717 functions in C++
LPU
 
Functions in c++
Functions in c++
Abdullah Turkistani
 
Functions in C++
Functions in C++
Mohammed Sikander
 
C++ functions
C++ functions
Dawood Jutt
 
Functions in C++ (OOP)
Functions in C++ (OOP)
Faizan Janjua
 
Functions in C++
Functions in C++
Nikhil Pandit
 
Inline Functions and Default arguments
Inline Functions and Default arguments
Nikhil Pandit
 
C++ Function
C++ Function
PingLun Liao
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
C++ Function
C++ Function
Hajar
 
C++ Functions
C++ Functions
sathish sak
 
C++ functions
C++ functions
Mayank Jain
 
C and C++ functions
C and C++ functions
kavitha muneeshwaran
 
Functions in C++
Functions in C++
home
 
Functions
Functions
Online
 
Functions in c++
Functions in c++
HalaiHansaika
 
Inline function
Inline function
Tech_MX
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
Arpee Callejo
 
functions of C++
functions of C++
tarandeep_kaur
 
Function in c++
Function in c++
Kumar
 
Function overloading
Function overloading
Selvin Josy Bai Somu
 
Functions in C++
Functions in C++
Pranali Chaudhari
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
Dheeraj Kataria
 
Function overloading(C++)
Function overloading(C++)
Ritika Sharma
 
Lecture#6 functions in c++
Lecture#6 functions in c++
NUST Stuff
 
Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
Functions
Functions
Golda Margret Sheeba J
 

More Related Content

What's hot (19)

Inline Functions and Default arguments
Inline Functions and Default arguments
Nikhil Pandit
 
C++ Function
C++ Function
PingLun Liao
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
C++ Function
C++ Function
Hajar
 
C++ Functions
C++ Functions
sathish sak
 
C++ functions
C++ functions
Mayank Jain
 
C and C++ functions
C and C++ functions
kavitha muneeshwaran
 
Functions in C++
Functions in C++
home
 
Functions
Functions
Online
 
Functions in c++
Functions in c++
HalaiHansaika
 
Inline function
Inline function
Tech_MX
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
Arpee Callejo
 
functions of C++
functions of C++
tarandeep_kaur
 
Function in c++
Function in c++
Kumar
 
Function overloading
Function overloading
Selvin Josy Bai Somu
 
Functions in C++
Functions in C++
Pranali Chaudhari
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
Dheeraj Kataria
 
Function overloading(C++)
Function overloading(C++)
Ritika Sharma
 
Lecture#6 functions in c++
Lecture#6 functions in c++
NUST Stuff
 
Inline Functions and Default arguments
Inline Functions and Default arguments
Nikhil Pandit
 
C++ Function
C++ Function
Hajar
 
Functions in C++
Functions in C++
home
 
Functions
Functions
Online
 
Inline function
Inline function
Tech_MX
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
Arpee Callejo
 
Function in c++
Function in c++
Kumar
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
Dheeraj Kataria
 
Function overloading(C++)
Function overloading(C++)
Ritika Sharma
 
Lecture#6 functions in c++
Lecture#6 functions in c++
NUST Stuff
 

Similar to Function class in c++ (20)

Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
Functions
Functions
Golda Margret Sheeba J
 
Functions
Functions
Lakshmi Sarvani Videla
 
Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptx
rayanbabur
 
Function different types of funtion
Function different types of funtion
svishalsingh01
 
C++.pptx
C++.pptx
AbhimanyuKumarYadav3
 
Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1
NageshPratapSingh2
 
Functions in Pythons UDF and Functions Concepts
Functions in Pythons UDF and Functions Concepts
nitinaees
 
Functions in C.pptx
Functions in C.pptx
Ashwini Raut
 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptx
urvashipundir04
 
object oriented programming language.pptx
object oriented programming language.pptx
syedabbas594247
 
Chp8_C++_Functions_Part2_User-defined functions.pptx
Chp8_C++_Functions_Part2_User-defined functions.pptx
ssuser10ed71
 
unit_2.pptx
unit_2.pptx
Venkatesh Goud
 
Chap 5 c++
Chap 5 c++
Venkateswarlu Vuggam
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 
OOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
arrays.ppt
arrays.ppt
Bharath904863
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
ArshiniGubbala3
 
Chap 5 c++
Chap 5 c++
Venkateswarlu Vuggam
 
Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptx
rayanbabur
 
Function different types of funtion
Function different types of funtion
svishalsingh01
 
Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1
NageshPratapSingh2
 
Functions in Pythons UDF and Functions Concepts
Functions in Pythons UDF and Functions Concepts
nitinaees
 
Functions in C.pptx
Functions in C.pptx
Ashwini Raut
 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptx
urvashipundir04
 
object oriented programming language.pptx
object oriented programming language.pptx
syedabbas594247
 
Chp8_C++_Functions_Part2_User-defined functions.pptx
Chp8_C++_Functions_Part2_User-defined functions.pptx
ssuser10ed71
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 
Ad

More from Kumar (20)

Graphics devices
Graphics devices
Kumar
 
Fill area algorithms
Fill area algorithms
Kumar
 
region-filling
region-filling
Kumar
 
Bresenham derivation
Bresenham derivation
Kumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons derication
Kumar
 
Introductionto xslt
Introductionto xslt
Kumar
 
Extracting data from xml
Extracting data from xml
Kumar
 
Xml basics
Xml basics
Kumar
 
XML Schema
XML Schema
Kumar
 
Publishing xml
Publishing xml
Kumar
 
DTD
DTD
Kumar
 
Applying xml
Applying xml
Kumar
 
Introduction to XML
Introduction to XML
Kumar
 
How to deploy a j2ee application
How to deploy a j2ee application
Kumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
Kumar
 
EJB Fundmentals
EJB Fundmentals
Kumar
 
JSP and struts programming
JSP and struts programming
Kumar
 
java servlet and servlet programming
java servlet and servlet programming
Kumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
Kumar
 
Introduction to J2EE
Introduction to J2EE
Kumar
 
Graphics devices
Graphics devices
Kumar
 
Fill area algorithms
Fill area algorithms
Kumar
 
region-filling
region-filling
Kumar
 
Bresenham derivation
Bresenham derivation
Kumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons derication
Kumar
 
Introductionto xslt
Introductionto xslt
Kumar
 
Extracting data from xml
Extracting data from xml
Kumar
 
Xml basics
Xml basics
Kumar
 
XML Schema
XML Schema
Kumar
 
Publishing xml
Publishing xml
Kumar
 
Applying xml
Applying xml
Kumar
 
Introduction to XML
Introduction to XML
Kumar
 
How to deploy a j2ee application
How to deploy a j2ee application
Kumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
Kumar
 
EJB Fundmentals
EJB Fundmentals
Kumar
 
JSP and struts programming
JSP and struts programming
Kumar
 
java servlet and servlet programming
java servlet and servlet programming
Kumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
Kumar
 
Introduction to J2EE
Introduction to J2EE
Kumar
 
Ad

Recently uploaded (20)

LDMMIA Shop & Student News Summer Solstice 25
LDMMIA Shop & Student News Summer Solstice 25
LDM & Mia eStudios
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
Aprendendo Arquitetura Framework Salesforce - Dia 02
Aprendendo Arquitetura Framework Salesforce - Dia 02
Mauricio Alexandre Silva
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Tanja Vujicic - PISA for Schools contact Info
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
parmarjuli1412
 
Photo chemistry Power Point Presentation
Photo chemistry Power Point Presentation
mprpgcwa2024
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
LDMMIA Shop & Student News Summer Solstice 25
LDMMIA Shop & Student News Summer Solstice 25
LDM & Mia eStudios
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Vitamin and Nutritional Deficiencies.pptx
Vitamin and Nutritional Deficiencies.pptx
Vishal Chanalia
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
Aprendendo Arquitetura Framework Salesforce - Dia 02
Aprendendo Arquitetura Framework Salesforce - Dia 02
Mauricio Alexandre Silva
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Tanja Vujicic - PISA for Schools contact Info
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
parmarjuli1412
 
Photo chemistry Power Point Presentation
Photo chemistry Power Point Presentation
mprpgcwa2024
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 

Function class in c++

  • 2. Inline Function Inline functions are functions where the call is made to inline functions. The actual code then gets placed in the calling program. Once you define an inline function, using the 'inline' keyword, whenever you call that function the compiler will replace the function call with the actual code from the function. General form inline datatype function_name(arguments)
  • 3. Inline Function #include <iostream> using namespace std; int func(int); void main( ) { int x; cout << "n Enter the Input Value: "; cin>>x; cout << "n The Output is: " << func(x); } inline int func(int x1) { return 5*x1; } Note:-Inline functions will save time and are useful if the function is very small. If the function is large, use of inline functions must be avoided.
  • 4. Function Overloading • Using same function name for different purposes is called function overloading. • Function will perform different operations depending on the argument list in the function call Ex. int add(int ,int) int add(int , float) int add(float ,int) int add(int ,int,int) • A function is executed when the function call matches the prototype with same number and type of argument.
  • 5. Function Overloading • Function selection involves the following steps.. 1. Tries to finds the exact match in which types of actual argument are same. 2. If actual match is not found then compiler uses the type coercion :promotion to find the match. 3. if conversion is possible to have multiple matches then compiler will generate the error. Ex . long sqr(long n) double sqr(double n) Function call sqr(10) cause the error.
  • 6. C structure revisited • Provides a method to packing together data of different type. Ex struct complex { int real; int img; }; struct complex c1,c2; Limitation of c structure: 1. c3=c1+c2 //illegal 2. Data hiding
  • 7. C++ structure • C++ supports all the features of the structures as defined in c. • C++ structure can have both function and data. • Support data hiding(by defining members as private). • Default members are public .
  • 8. Class • A class is a user defined data type • General form of class declaration class class_name { private: variable declaration; function declaration; public: variable declaration; function declaration; };
  • 9. Class • function and variable collectively called class members. • Variables declared inside the class is known as data member and function declared inside the class is known as member function. • Only the member function can have access to the private data member and private member function. • Default members are private.
  • 10. Class declaration • Class declaration:class item{ int number; //variable declaration float price; public: void getdata(int ,float); //function declaration void putdata(void); };
  • 11. Defining member function • Member function can be defined in two places 1. Outside the class definition. 2. Inside the class definition
  • 12. Outside the class definition • Genral form :Return_type class_name::function_name(parameter list) { function body; } Ex . void item :: getdata(int x,float y) { number=x; price=y; }
  • 13. Inside the class definition • Genral form :Return_type function_name(parameter list) { function body; } Ex . void getdata(int x,float y) { number=x; price=y; }
  • 14. Accessing members of a class • Accessing data members object_name.datamember; • Accessing member function object_name.function(actual parameters); item m; m.getdata(5,6.5) Note : Members are called by using their name only inside the member function.
  • 15. Private Member Function • A private member function can only be called by another function that is member of its class even an object can not invoke the private function of a class using the dot operator. Class sample { int main() int m; { void read(void) sample s1; public: s1.read(); //error void update(void); s1.update(); }; } void sample :: update(void) { read(); //simple call no object is used }