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 */
cout<<m
}
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.
 

0 Comments:

Post a Comment

Popular Posts

Categories

AI (33) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (21) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (893) Python Coding Challenge (285) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

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