What are the problems in the code below? (pick 4) int print(int, int); float mai
ID: 3687006 • Letter: W
Question
What are the problems in the code below? (pick 4)
int print(int, int); float main() {
int x = 2; int y = 3; cout << “Hello ” << endl; return print(y, x);
}
void print(int num1, num2)
{
cout << “World! << endl; return (num1 + num2);
}
The arguments and parameters for print() are not consistent.
Main cannot have a return type of float
The function prototype incorrectly declares the parameters.
The return type of print() is void in its header, but it returns an int and the prototype says it should return int.
The return statement in print() cannot return the value of an expression.
There should not be a semicolon at the end of the prototype.
main() must return a int, but the return statement returns the return value of print(), which may be void (based on the function header).
The prototype parameters for print() are not correctly specified.
Explanation / Answer
The arguments and parameters for print() are not consistent.
Main cannot have a return type of float: main function should return an integer, and not a float.
The function prototype incorrectly declares the parameters.: Every parameter should have a datataype. But the second parameter is not given a datatype.
The return type of print() is void in its header, but it returns an int and the prototype says it should return int.
The return statement in print() cannot return the value of an expression.
There should not be a semicolon at the end of the prototype.
main() must return a int, but the return statement returns the return value of print(), which may be void (based on the function header).: Unless you change the print() return type to int, this could be the reason.
The prototype parameters for print() are not correctly specified. There should be the datatype for every parameter specified. So, it should be void print(int num1, int num2), and the prototypes should match. In the declaration, the return type is int, whereas in the definition, the return type is specified as void.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.