Tuesday 27 March 2018

Function Calls

A function cab be called by simply using function name followed by a list of actual parameters (or arguments) if any, enclosed in parentheses.
For example:
main( )
float m;
m = mul(5.2, 3.17); /* function call */
When compiler encounters the function call, it transfer program control to the function mul( ) by passing values 5.2 and 3.17 (actual parameters) to the formal parameters on the function mul( ). The mul( ) will performs operations on these values and then returns the result. It will be stored in variable m. We are printing the value of variable m on the screen. There are a number of different ways in which the function can be called as given below:

mul(5.2, 3.71);
mul(m, 3.17);
mul(5.2, m);
mul(m, n);
mul(m+5.1, 3.17);
mul(m+3.6, m+9.1);
mul(mul(6.1,8.2), 4.5); 
Only we have to remember that the function call must satisfy type and number of arguments passed as parameters to the called function.

Function Prototype / Function Declaration
 Like variables, all functions in C++ program must be declared, before they are used in calling function. This declaration of function is known as prototype. It having following syntax of use:

function_type function_name (parameter list);  

 this is very similar to function header except the terminating semicolon.
For example, the function mul( ) will be declared as,
float mul(float, float);
Generally, prototype declarations as not necessary, if the function have been declared before it is used. A prototype declarations my be placed in two places in the program.
  • Above all the functions
  • Inside function definition
  We place declaration above all the functions this prototype is known as global prototype. That is, we can use this function in any part on the program. When we place the function definition in the local declaration section of another it is referred as local prototype.


Post a Comment

Popular Posts


AI (28) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (121) C (77) C# (12) C++ (82) Course (66) Coursera (184) Cybersecurity (24) data management (11) Data Science (99) Data Strucures (7) Deep Learning (11) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Pandas (3) PHP (20) Projects (29) Python (791) Python Coding Challenge (268) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (41) UX Research (1) web application (8)


Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses