{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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);

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

View Full Document
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
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; }

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

View Full Document
Example Example #include <iostream.h> int Sum ( int A,
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}