Consider the following variable definitions and function call: string customer =
ID: 3883632 • Letter: C
Question
Consider the following variable definitions and function call:
string customer = "Customer1";
float balance;
float amount = 72.56;
char type = S;
getBalance(customer, balance, type, 200.53);
Consider the two function headers below. For each header, say if you think the header for function getBalance is a valid header, and give reasons for your answer:
1. void getBalance(string customerP, float & balAmnt, char & typeC, float & amtC);
2. void getBalance(string customerP, float & balAmnt, char & typeC, float amtC);
Explanation / Answer
header1-
void getBalance(string customerP, float &balAmnt,char &typeC,float &amtC)- this header is not valid because in the last declaration in the function call getBalance(customer, balance, type, 200.53); we are passing a constant value and in the function header we are pasiing the address of the variable amtC so in function call we should be a variable whose address could be accessed but in the function call we are pasiing a constant so it is not a valid header.
header2-
void getBalance(string customerP, float & balAmnt, char & typeC, float amtC); this is a valid header for the function call as in the function header we are using &balAmnt and &typeC that means we are accessing the value of the variable through its address and in the function we have provided the variable and not a constant so it will execute without any errors.
if this answer is a valid answer or you get to understand the answer please do provide the rating.