Question
` Definitions We will define several terms you need to know to really understand functions. They are as follows: Formal parameters reside inside a function
`
Definitions
We will define several terms you need to know to really understand functions. They are as follows:
Formal parameters reside inside a function header. They allow the actual arguments to be passed to a function. The scope of formal parameters is local to the function where they are declared.
Actual arguments reside in the function that did the invocation (call). Their values are passed to the called function through the formal parameters.
The header of a function includes the function return type, the function name, and the formal parameter list enclosed in parenthesis.
The signature of a function includes the function name and the formal parameter list enclosed in parenthesis.
The function prototype includes the function return type, the function name, and the formal parameter list enclosed in parenthesis. The prototype ends with a semi-colon.
Function declarations (prototypes) provide information to the compiler to aid in the setup for a function call.
Declaration Syntax
There are two ways to code a function declaration:
Function_return_type Function_name (Type1 FF1, Type2 FF2, , TypeN FFN);
or the alternative syntax
Function_return_type Function_name (Type1, Type2, , TypeN);
Note:
Type1, Type2, , TypeN refer to the data types of the formal parameters.
FF1, FF2, , FFN refer to the names of the formal parameters
All declarations end with a ;.
More information on functions can be found in your course textbook and on the web.
Experiments
Question 1:What are the differences between the two function declarations shown above?
Question 2:Based on our previous lab, we learned about data types and the size of space allocated in memory [for instance an int may take up 4 bytes of space]. Based on this knowledge and different ways to write a prototype, what observations can you make regarding how a compiler knows how much space to allocate?
Question 3:What specific information does the compiler need to perform a successful function call?
Question 4:Write the header and signature for the following function. Also write the two forms of its prototype.
double Print_Message(double balance, double limit)
{
if (limit > 0)
{
cout<<"Your Balance is $"< cout<<"Your have money. Proceed with your transaction "; } else { cout<<"Your Balance is $"< cout<<"Your transaction has been cancelled "; } return balance } int main() { double balance = 99.99, limit = 2000.22; cout<<"Balacne and Limt have the following values before Print_Message is called"< cout<<"balance= "< cout<<"Balance = "< There are 3 Steps involved in it See step-by-step solutions with expert insights and AI powered tools for academic successStep by Step Solution
Step: 1
Get Instant Access to Expert-Tailored Solutions
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started