Define the following terms: (4 pts) 1.function prototype 2.parameters 3.argument
ID: 3902406 • Letter: D
Question
Define the following terms: (4 pts)
1.function prototype
2.parameters
3.arguments
4.return value
What type of value should the following function return: (1 pt)
int minInt(int, int, int);
All of the following are valid arguments for any one of the parameters in the function in Question 2. except: (1 pt)
1.(int)sqrt(81);
2.a + b //where a and b are int variables
3.43
4.all are valid arguments
Every C++ function must always have a return statement. (T / F) (1 pt)
Write the function prototype for a function that returns the string equivalent of a double precision floating point number passed as an argument. (3 pts)
Explanation / Answer
Answer:
Question1
1.function prototype: A function prototype or function definition that specifies the function's name and type (arity, data types of parameters, and return type), but omits the function body.
For example: int add(int,int);
The above example represents a function prototype. 'add' is the name of the function, (int,int) are the types of parameters of 'add' function, int (before the function name 'add') is the return type of 'add' function.
The meaning of the above declaration is add function takes two integer arguments and it returns an integer to the calling function.
2,3 parameters/arguments: The actual input supplied in the function call is called actual parameters/actual arguments. whereas the variables used in function definition is called formal arguments/formal parameters.
For example: sum=add(2,3); /* function call (2, 3 are actual parameters) */
int add(int x,int y) /* function definition (x and y are formal parameters)*/
{
int z;
z=x+y;
return z;
}
4.return value: A function may or may not return a value to the calling function. If a function doesn't return any value means the return type is 'void'. If a function returns a value means It is specified by the data type.
For example: In the above example return z is the statement to return the value stored in z (an integer, because z is a variable of type integer) to the calling function.
Question2
What type of value should the following function return:
int minInt(int, int, int);
The above function returns an integer value to the calling function as the return type is 'int'
Question3
All of the following are valid arguments for any one of the parameters in the function in Question 2.
1.(int)sqrt(81); // sqrt(81) is 9, (int)9 is an integer, so it is a valid argument to the above function
2.a + b //where a and b are int variables// Addition of two integers (a+b) is an integer, so it is a valid argument
3.43 //43 is an integer, so it is a valid argument
4.all are valid arguments
Question4
Every C++ function must always have a return statement.
Answer is FALSE (A C++ function may or may not return a value. It is not mandatory that a function returns a value)
Question5
Write the function prototype for a function that returns the string equivalent of a double precision floating point number passed as an argument.
The Answer is
string functionname(double);
For example
string func(double d)
{
string s;
s=d;
return s;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.