Simple Homework problem

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
Last edited on
Study hard and good luck!
You should be able to run these code snippets through the compiler -- it will tell you the answers.
Ok looking at that I would say 1.)b, 2.)a, 3.)b

Does that look right?
Last edited on
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.
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
Nope, wrong again.

ary has type int[]
ary[0] has type int

functions takes int[] as parameter
Topic archived. No new replies allowed.