











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Following points have been discussed in these lecture slides by Baljit Ashvin at Indian Institute of Information Technology (IIIT) under subject of Computer Fundamentals: Functions, Prototype, Definition, Generic, Structure, Body, Main, Return, Type, Arguments
Typology: Slides
1 / 19
This page cannot be seen from the preview
Don't miss anything!












return type function_name (function arguments) {
Function body
return (optional) value;
}
----header files ---
void aboutMe(void);
void main(void){
cout<<“Hello”; aboutMe();
}
void aboutMe(void){
cout<<“My name is Alpha”<<endl; cout<<“Address: Islamabad”<<endl; cout<<“Cell: 123456789”<<endl;
}
Prototype
Definition
Output Hello My name is Alpha Address :Islamabad Cell:
int myFunction1(void); the function should return an integer float myFunction2(void); the function should return a float double myFunction3(void); the function should return a double long int myFunction4(void); the function should return a long integer
Example ---header files--- float height(void); int weight(void);
void main(void){ cout<<“Hello my name is Alpha”<<endl; cout<<“My weight is ”<<weight()<<endl; cout<<“My height is ”<<height()<<endl; }
int height(void){ return 5.6; }
int weight(void){ int w=55; return w; }
Output Hello my name is Alpha My weight is 55 My height is 5.
int add(int , int); two arguments of type integer can be passed int mul(int,int); same int remainder(int,int); same float divide(float,int); two arguments , first float and second integer can be passed
---header files--- int add(int,int);
void main(void ){ int result; cout<<“The sum of 5 and 10 is =”<<add(5,10)<<endl; result=add(40,50); cout<<“The sum of 40 and 50 is ”<<result<<endl; }
int add(int a, int b){ int sum; sum=a+b; return sum }
Output The sum of 5 and 10 is 15 The sum of 40 and 50 is 90
---definitions of all functions-----
main(){
function1(); function2();
function3(); function4();
function5();
}
A when a function is called it is placed on stack , after function finishes its
work it is removed from the stack.
What is the life of variables in the function?
main() var1,var
function1() var3,var function2() Var5,var function3() var7,var
function4() var9,var
function5() Var11,var