Source: Let us C by Yashwant Kanitkar
Functions
• named block of code
• perform some actions.
• executed when called by name.
• Unique name.
Source: Let us C by Yashwant Kanitkar
.. Building blocks of Function :
•provide a structured programming
approach.
•modular way of programming.
• The whole program logic is divided
into smaller modules or functions.
Types of Functions
C++ language provides the
following types of functions:
User Defined Functions
Built in Function
Source: Let us C by Yashwant Kanitkar
User Defined Functions
A type of function written by programmer
is known as user-defined function.
User defined function has a unique name.
User-defined function consist of the
following:
 Function declaration
 Function definition
Source: Let us C by Yashwant Kanitkar
Built – in Function
A type of function that is available as a
part of language is known as built - in
function or library function . There
are many functions and some of
those are:
 sqrt(number);
 pow(x,y);
 rand( );
 clock( );
Source: Let us C by Yashwant Kanitkar
Returning Value from
Function
 can return a single value.
 indicates the type of value
For example
int is used as return type
 if the function returns the integer value .
Syntax
The syntax for returning a value is as follows:
return expression;
Source: Let us C by Yashwant Kanitkar
Program
#include <iostream.h>
#include <conio.h>
Int cube(int);
Void main()
{
int n , c;
cout<<“Enter number:”;
cin>>n;
c = cube(n);
cout<<“cube is”<<c;
getch();
}
Int cube(int num)
{
return num * num * num;
}
Enter number : 4
Cube is : 64
Output
Returning value
Example:
Source: Let us C by Yashwant Kanitkar
Any Question ?
Any Question ?

Functions

  • 1.
    Source: Let usC by Yashwant Kanitkar
  • 2.
    Functions • named blockof code • perform some actions. • executed when called by name. • Unique name. Source: Let us C by Yashwant Kanitkar
  • 3.
    .. Building blocksof Function : •provide a structured programming approach. •modular way of programming. • The whole program logic is divided into smaller modules or functions.
  • 4.
    Types of Functions C++language provides the following types of functions: User Defined Functions Built in Function Source: Let us C by Yashwant Kanitkar
  • 5.
    User Defined Functions Atype of function written by programmer is known as user-defined function. User defined function has a unique name. User-defined function consist of the following:  Function declaration  Function definition Source: Let us C by Yashwant Kanitkar
  • 6.
    Built – inFunction A type of function that is available as a part of language is known as built - in function or library function . There are many functions and some of those are:  sqrt(number);  pow(x,y);  rand( );  clock( ); Source: Let us C by Yashwant Kanitkar
  • 7.
    Returning Value from Function can return a single value.  indicates the type of value For example int is used as return type  if the function returns the integer value . Syntax The syntax for returning a value is as follows: return expression; Source: Let us C by Yashwant Kanitkar
  • 8.
    Program #include <iostream.h> #include <conio.h> Intcube(int); Void main() { int n , c; cout<<“Enter number:”; cin>>n; c = cube(n); cout<<“cube is”<<c; getch(); } Int cube(int num) { return num * num * num; } Enter number : 4 Cube is : 64 Output Returning value Example: Source: Let us C by Yashwant Kanitkar
  • 9.
  • 10.