SlideShare a Scribd company logo
2
Introduction
 Use of function
   Calling a formula defined by user
   Input & Output depends on type of function


 Not included in main body


 Can be called many times
Most read
3
Function Prototype
 After #include<iostream>
 Before int main()

    Example 1

    # include <iostream>

    void FindMax(int, int); //prototype

    using namespace std;
    int main()
Most read
Function
Introduction
 Use of function
   Calling a formula defined by user
   Input & Output depends on type of function


 Not included in main body


 Can be called many times
Function Prototype
 After #include<iostream>
 Before int main()

    Example 1

    # include <iostream>

    void FindMax(int, int); //prototype

    using namespace std;
    int main()
4




Calling Function
Example 2

int main()
{
    int num1, num2;
    cout<<"Please enter a number :";
    cin>> num1;
    cout<<"Great!nPlease enter a second number :";
    cin>> num2;
    FindMax(num1, num2); //calling function

     system ("PAUSE");
     return 0;
}
Defining Function
 Outside main body
 Example 3

 void FindMax(int x, int y){
      int maxNum;
      if (x>=y)
      maxNum=x;
      else
      maxNum=y;
      cout<<"Maximum number is : "<<maxNum <<endl;
      }
Using reference variable
 The Prototype:
    void FindMax(double, double, double&);


 The Calling:
    FindMax(num1, num2, maxNum);


 The Defining:
    void FindMax(double x, double y, double& maxNum)


 maxNum: a value edited in main function
•   Compare Example 2

Example 4

int main()
{
    double num1, num2, maxNum;
    cout<<"Please enter a number :";
    cin>> num1;
    cout<<"Great!nPlease enter a second number :";
    cin>> num2;
    FindMax(num1, num2, maxNum); //calling

     system ("PAUSE");
     return 0;
}

                                          Go to DevC++
Looping Function
 Just insert function in loop to call as needed
 Looping with returned value :
    Declare return value
    Send value to function


 Write a loop
   Example :
       Using while loop to keep comparing numbers
Example 5

char next;
while(true){
   cout<<"n('n' to exit')Compare with next number? :";
   cin>> next;
   if(next=='n')
   break;
   cout<<"Okay!nPlease enter the next number :";
   cin>> num1;
   num2 = maxNum;
   FindMax(num1, num2, maxNum);
   }
END

More Related Content

What's hot (20)

C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
Function overloading
Function overloadingFunction overloading
Function overloading
Selvin Josy Bai Somu
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
Prabhu Govind
 
Function in c
Function in cFunction in c
Function in c
Raj Tandukar
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
 
C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
•sreejith •sree
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Function in c
Function in cFunction in c
Function in c
savitamhaske
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Sikder Tahsin Al-Amin
 
C if else
C if elseC if else
C if else
Ritwik Das
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Function
FunctionFunction
Function
jayesh30sikchi
 
Exceptions in python
Exceptions in pythonExceptions in python
Exceptions in python
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
Rodolfo Finochietti
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
Prof. Dr. K. Adisesha
 

Viewers also liked (20)

functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Function in c++
Function in c++Function in c++
Function in c++
Kumar
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Functions
FunctionsFunctions
Functions
Online
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Jenish Patel
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
7 Slide Summary: HOW can India's Parliament function better?
7 Slide Summary: HOW can India's Parliament function better?7 Slide Summary: HOW can India's Parliament function better?
7 Slide Summary: HOW can India's Parliament function better?
Yogesh Upadhyaya
 
02. functions & introduction to class
02. functions & introduction to class02. functions & introduction to class
02. functions & introduction to class
Haresh Jaiswal
 
Dynamics Behaviour of Multi Storeys Framed Structures by of Iterative Method
Dynamics Behaviour of Multi Storeys Framed  Structures by of Iterative Method Dynamics Behaviour of Multi Storeys Framed  Structures by of Iterative Method
Dynamics Behaviour of Multi Storeys Framed Structures by of Iterative Method
AM Publications
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMSPARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
Arpee Callejo
 
What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
Trees
TreesTrees
Trees
Sadaf Ismail
 
EEE 3rd year oops cat 3 ans
EEE 3rd year  oops cat 3  ansEEE 3rd year  oops cat 3  ans
EEE 3rd year oops cat 3 ans
Karthik Venkatachalam
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
indiangarg
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
Supriya Radhakrishna
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Function in c++
Function in c++Function in c++
Function in c++
Kumar
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Functions
FunctionsFunctions
Functions
Online
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Jenish Patel
 
7 Slide Summary: HOW can India's Parliament function better?
7 Slide Summary: HOW can India's Parliament function better?7 Slide Summary: HOW can India's Parliament function better?
7 Slide Summary: HOW can India's Parliament function better?
Yogesh Upadhyaya
 
02. functions & introduction to class
02. functions & introduction to class02. functions & introduction to class
02. functions & introduction to class
Haresh Jaiswal
 
Dynamics Behaviour of Multi Storeys Framed Structures by of Iterative Method
Dynamics Behaviour of Multi Storeys Framed  Structures by of Iterative Method Dynamics Behaviour of Multi Storeys Framed  Structures by of Iterative Method
Dynamics Behaviour of Multi Storeys Framed Structures by of Iterative Method
AM Publications
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMSPARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
Arpee Callejo
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
indiangarg
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
Jeba Moses
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
Supriya Radhakrishna
 
Ad

Similar to C++ programming function (20)

C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
Silde of the cse fundamentals a deep analysis
Silde of the cse fundamentals a deep analysisSilde of the cse fundamentals a deep analysis
Silde of the cse fundamentals a deep analysis
Rayhan331
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
TAlha MAlik
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
jleed1
 
Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01
Abdul Samee
 
Function
FunctionFunction
Function
venkatme83
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
harman kaur
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
temkin abdlkader
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
C++ Language
C++ LanguageC++ Language
C++ Language
Syed Zaid Irshad
 
Programming Fundamentals lecture-10.pptx
Programming Fundamentals lecture-10.pptxProgramming Fundamentals lecture-10.pptx
Programming Fundamentals lecture-10.pptx
singyali199
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
TarekHemdan3
 
Object Oriented Programming (OOP) using C++ - Lecture 5
Object Oriented Programming (OOP) using C++ - Lecture 5Object Oriented Programming (OOP) using C++ - Lecture 5
Object Oriented Programming (OOP) using C++ - Lecture 5
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
functions
functionsfunctions
functions
teach4uin
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
NagasaiT
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
mallik3000
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
rohassanie
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
WaheedAnwar20
 
Pointer to Member Function.pptx pointer in c++
Pointer to Member Function.pptx pointer in c++Pointer to Member Function.pptx pointer in c++
Pointer to Member Function.pptx pointer in c++
ankeshshri
 
Pro
ProPro
Pro
TeshaleSiyum
 
Silde of the cse fundamentals a deep analysis
Silde of the cse fundamentals a deep analysisSilde of the cse fundamentals a deep analysis
Silde of the cse fundamentals a deep analysis
Rayhan331
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
TAlha MAlik
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
jleed1
 
Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01Part 3-functions1-120315220356-phpapp01
Part 3-functions1-120315220356-phpapp01
Abdul Samee
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
harman kaur
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
Programming Fundamentals lecture-10.pptx
Programming Fundamentals lecture-10.pptxProgramming Fundamentals lecture-10.pptx
Programming Fundamentals lecture-10.pptx
singyali199
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
NagasaiT
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
mallik3000
 
Pointer to Member Function.pptx pointer in c++
Pointer to Member Function.pptx pointer in c++Pointer to Member Function.pptx pointer in c++
Pointer to Member Function.pptx pointer in c++
ankeshshri
 
Ad

Recently uploaded (20)

Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
UiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build PipelinesUiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build Pipelines
UiPathCommunity
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
UiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build PipelinesUiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build Pipelines
UiPathCommunity
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 

C++ programming function

  • 2. Introduction  Use of function  Calling a formula defined by user  Input & Output depends on type of function  Not included in main body  Can be called many times
  • 3. Function Prototype  After #include<iostream>  Before int main() Example 1 # include <iostream> void FindMax(int, int); //prototype using namespace std; int main()
  • 4. 4 Calling Function Example 2 int main() { int num1, num2; cout<<"Please enter a number :"; cin>> num1; cout<<"Great!nPlease enter a second number :"; cin>> num2; FindMax(num1, num2); //calling function system ("PAUSE"); return 0; }
  • 5. Defining Function  Outside main body Example 3 void FindMax(int x, int y){ int maxNum; if (x>=y) maxNum=x; else maxNum=y; cout<<"Maximum number is : "<<maxNum <<endl; }
  • 6. Using reference variable  The Prototype:  void FindMax(double, double, double&);  The Calling:  FindMax(num1, num2, maxNum);  The Defining:  void FindMax(double x, double y, double& maxNum)  maxNum: a value edited in main function
  • 7. Compare Example 2 Example 4 int main() { double num1, num2, maxNum; cout<<"Please enter a number :"; cin>> num1; cout<<"Great!nPlease enter a second number :"; cin>> num2; FindMax(num1, num2, maxNum); //calling system ("PAUSE"); return 0; } Go to DevC++
  • 8. Looping Function  Just insert function in loop to call as needed  Looping with returned value :  Declare return value  Send value to function  Write a loop  Example :  Using while loop to keep comparing numbers
  • 9. Example 5 char next; while(true){ cout<<"n('n' to exit')Compare with next number? :"; cin>> next; if(next=='n') break; cout<<"Okay!nPlease enter the next number :"; cin>> num1; num2 = maxNum; FindMax(num1, num2, maxNum); }
  • 10. END