• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » C++ » Functions » Invoking Functions in C++
Next →
← Prev

Invoking Functions in C++

By Dinesh Thakur

In order to use a function in different parts of a program, the function must be called or invoked by another function. In C++, functions are called by specifying the name of the function, followed by the parentheses. The parentheses mayor may not contain a list of arguments depending on the function definition.

The syntax for invoking a function is

function_name (argl, arg2, ... , argN);

where,

function_name = the name of the function

argl, arg2, … , argN = the list of arguments

The function that calls another function is known as the calling function and the function that is being called is known as the called function. When a function is called, the control immediately passes from the calling function to the called function. The called function then executes its body after which the control returns to the next statement in the calling function.

To understand the concept of invoking the function, consider this example.

Example: A program to demonstrate the invoking of a function

#include<iostream>
using namespace std;
void disp () ;
int main () {
  cout<< "Welcome to Calling function" <<endl;
  disp ( ) ; // invoking disp ( )
  cout<<"Back to Calling function"<<endl;
  return 0;
}
void disp () { 
  cout<<"Welcome to Called function"<<endl;
}

The output of the program is

Welcome to calling function

Welcome to Called function

Back to calling function

In this example, the function disp() is invoked from the function main (). Thus, the function main () is the calling function and the function disp () is the called function.

Generally, the calling function passes information to the called function through arguments. The argument(s) that appear in the function call are known as actual arguments and the argument(s) that appear in the function definition are known as formal arguments. The number of actual arguments, their order and type in the function call must match with that of the formal arguments.

To understand the concept of actual and formal arguments, consider this example.

Example: A program to demonstrate the use of actual and formal argument

The output of the program is

#include<iostream>
using namespace std;
void sum (int, int) ;
int main () {
  int a,b;
  cout<<"Enter the first no. :“;
  cin>>a;
  cout<<"Enter the second no.:”;
  cin>>b;
  sum(a,b) ;
  return 0;
} 
void sum(int x, int y) {
   cout<<"The sum is : "<<(X+Y);
}

Enter the first no. 25

Enter the second no. : 25

The sum is : 50

In this example, the function sum ( ) is invoked with two actual arguments, namely, a and b. The values of these arguments are passed to two formal arguments, namely, x and y. Note that the number of actual arguments and their data types are same as the formal arguments.

You’ll also like:

  1. What is Functions? Explain Features of Functions,Types of Functions and Calling a Function
  2. What is Destructor in C++
  3. PHP Functions:User-defined functions
  4. Static Variables Within Functions in C ++
  5. Functions With or Without Return Value
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

C++ Tutorials

C++ Tutorials

  • C++ - Data Types
  • C++ - Operators Types
  • C++ - CPP Program Structure
  • C++ - Conditional Statements
  • C++ - Loop
  • C++ - do-While Loop
  • C++ - Control Statements
  • C++ - Tokens
  • C++ - Jump Statements
  • C++ - Expressions
  • C++ - Constants
  • C++ - Character Set
  • C++ - Iteration Statements
  • C++ - I/O Statements
  • C++ - String
  • C++ - Manipulators

C++ Operator

  • C++ - Input/Output Operator
  • C++ - Operator Overloading

C++ Functions

  • C++ - Functions
  • C++ - Member Functions
  • C++ - Returning Object from Function
  • C++ - Call by Value Vs Reference
  • C++ - Friend Function
  • C++ - Virtual Function
  • C++ - Inline Function
  • C++ - Static Data Members
  • C++ - Static Member Functions

C++ Array & Pointer

  • C++ - Array
  • C++ - Array of Objects
  • C++ - Arrays as Class Members
  • C++ - Vector
  • C++ - Pointer
  • C++ - 'this' Pointer

C++ Classes & Objects

  • C++ - Class
  • C++ - Program Structure With Classes
  • C++ - OOP’s
  • C++ - Objects as Function Arguments
  • C++ - Procedure Vs OOL
  • C++ - Object Vs Class
  • C++ - Creating Objects
  • C++ - Constructors
  • C++ - Copy Constructor
  • C++ - Constructor Overloading
  • C++ - Destructor
  • C++ - Polymorphism
  • C++ - Virtual Base Class
  • C++ - Encapsulation

C++ Inheritance

  • C++ - Inheritance
  • C++ - Multiple Inheritance
  • C++ - Hybrid Inheritance
  • C++ - Abstraction
  • C++ - Overloading

C++ Exception Handling

  • C++ - Exception Handling
  • C++ - Templates
  • C++ - Standard Template Library

C++ Data Structure

  • C++ - Link List

C++ Programs

  • C++ Program for Electricity Bill
  • C++ Program for Multiply Matrices
  • C++ Program for Arithmetic Operators
  • C++ Program For Matrices
  • C++ Program for Constructor
  • C++ Program Verify Number
  • C++ Program Array Of Structure
  • C++ Program to find Average Marks
  • C++ Program Add And Subtract Matrices
  • C++ Program Menu Driven
  • C++ Program To Simple Interest
  • C++ Program To Find Average
  • C++ program exit()
  • C++ Program Using Array Of Objects
  • C++ Program Private Member Function
  • C++ Program To Reverse A String
  • C++ Program to Operator Overloading

Other Links

  • C++ - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW