PPT-functions in C
PPT-functions in C
PPT-functions in C
Return_type
function_name
(arguments list)
function definition { Body of function; }
function_name
function call (arguments list);
return_type
function_name
function declaration (argument list);
SIMPLE EXAMPLE PROGRAM FOR C
FUNCTION
• As you know, functions should be declared
and defined before calling in a C program.
• In the below program, function “square” is
called from main function.
• The value of “m” is passed as argument to the
function “square”. This value is multiplied by
itself in this function and multiplied value “p”
is returned to main function from function
“square”.
Conti..
#include<stdio.h>
// function prototype, also called function declaration
float square ( float x );
// main function, program starts from here
int main( )
{
float m, n ;
printf ( "\nEnter some number for finding square \n");
scanf ( "%f", &m ) ;
// function call
n = square ( m ) ;
printf ( "\nSquare of the given number %f is %f",m,n );
}
int main()
{
int m = 22, n = 44;
// calling swap function by value
printf(" values before swap m = %d \nand n = %d", m, n);
swap(m, n);
}
int main()
{
int m = 22, n = 44;
// calling swap function by reference
printf("values before swap m = %d \n and n = %d",m,n);
swap(&m, &n);
}