Nov 12, 2010 at 6:18pm UTC
I am stuck on a couple of problems from my C++ homework.
1.) Consider the following function prototype:
void f1(int[]);
If an array has been created as follows:
int ary[4] = {0};
Which is a valid call to the function?
Choose one answer.
a. f1(ary);
b. f1(ary[0]);
c. both are valid
2.) The following function prototypes are used in a .cpp file
int m1(double);
int m1(int);
Choose one answer.
a. This is a valid function overload
b. This is an invalid function overload
3.) The following function prototypes have been coded in a .cpp file
void m1(int);
int m1(int);
Choose one answer.
a. This is a valid function overload
b. This is an invalid function overload
Nov 12, 2010 at 6:27pm UTC
Last edited on Nov 12, 2010 at 6:27pm UTC
Nov 12, 2010 at 6:28pm UTC
Study hard and good luck!
Nov 12, 2010 at 7:04pm UTC
You should be able to run these code snippets through the compiler -- it will tell you the answers.
Nov 12, 2010 at 7:25pm UTC
Ok looking at that I would say 1.)b, 2.)a, 3.)b
Does that look right?
Last edited on Nov 12, 2010 at 7:30pm UTC
Nov 12, 2010 at 7:27pm UTC
1.) Incorrect. Look over the section on arrays and look carefully for how to pass them to functions.
2.) Correct.
3.) Correct. You can't overload on return type alone.
Nov 12, 2010 at 7:32pm UTC
Ah it would be c, because in the guide it says:
it would be enough to write a call like this:
procedure (myarray);
So a. f1(ary); would be valid as well
Nov 12, 2010 at 9:04pm UTC
Nope, wrong again.
ary has type int[]
ary[0] has type int
functions takes int[] as parameter