Академический Документы
Профессиональный Документы
Культура Документы
#include <stdio.h>
void main()
{
message();
printf(\n Ahmedabad);
}
void message()
{
printf(PRO);
}
O/P:
PRO
Ahmedabad
return(expression)
}
void main()
o/p: PRO
{
Ahmedabad
dispname();
www.xyz.com
dispcity();
+91-0000
dispweb();
dispcontact();
}
void dispname()
{printf(PRO);}
void dispcity()
{printf(Ahmedabad);}
void dispweb()
{printf(www.xyz.com);}
void dispcontact()
{printf(+91-0000);
main ( )
{
function ( )
{
task
}
}
1) Library Functions
2) User Defined Functions
Library Functions : Commonly required functions
grouped together and stored in what is called a
Library.
This Library is present on the disk and is written for us
by peoples who write compilers for us.
doing.
Operation of the program is divided into different
activity & each activity is placed in different functions.
Thus separating code into modular functions also
makes the program easier to design and understand.
Dont try to pack the whole logic in one function.
void main()
{
int a, b, c, avg;
printf(Enter 3 numbers.).
scanf(%d %d %d,&a,&b,&c);
avg= findavg(a, b, c);
printf(Average is %d. , avg);
}
int findavg(int x, int y, int z)
{
int ans;
ans = (x + y + z)/3;
//int. average
return(ans);
}
Method 1
function ( a, b, c )
int a , b , c ;
Here declaration is done in separate statement.
This method is known as K & R method.
Method 2
function
Returns the value present in ( ) example : return ( a )
return ;
will return a garbage value to the calling function
if we want that the called function should not return a
value at that time we must use void type for the
function.
Example:
void display ( )
{
function body
}
}
float func_a( arguments );
{
function body
}
Call by Value :
on calling a function we are passing values of variables
to it.
Call by Reference :
Instead of passing the value, we pass the address of the
variables
THANK YOU