{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

23.Function - Function Function User defined function is a...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Function Function User defined function is a code segment (block) that perform an specific action and may return a value. Function Definition: Function Definition: Return_DT F_name ( list of formal parameters) { Action_ body ; } If Return_DT is void Then: Action_body doesn’t contain return statement. Else: Action_body contains return statement. Calling (invoking) Function: Calling (invoking) Function: F_name (Actual parameters);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Example Example #include <iostream.h> int Max ( int Value1, int Value2) { if (Value1 > Value2) return Value1; else return Value2; } void main() { int a, b; cout<<"\nPlease Enter the values of a and b: "; cin>>a>>b; cout<<"\n the maximum one is: "<<Max(a,b)<<endl; } Function Definition Calling the function in an expression like cout<<, condition, assignment statements
Background image of page 2
Example Example #include <iostream.h> int Max ( int Value1, int Value2) { if (Value1 > Value2) return Value1; else return Value2; } void main() { int a, b; cout<<"\nPlease Enter the values of a and b: "; cin>>a>>b; cout<<"\n the maximum one is: "<<Max(a,b)<<endl; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Example Example #include <iostream.h> int Sum ( int A,
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}