Which of the following function declarations with default ar

Which of the following function declarations with default arguments are correct? Select one or more. void g(int length, int width, int height = 1); void g(int length=1, int widths=1, int height); void g(int length, int width=1, int height = 1); void g(int length=1, int width, int height);

Solution

a. void g(int length, int width, int height = 1); will have a default value of 1 to height.

b. This is invalid assignment. Always, default values should be specified from right to left.

c. void g(int length, int width = 1, int height = 1); will have a default value of 1 to height if 2 parameters are passed, and will have a default value of 1 to both width and height if 1 parameter is passed.

d. Again, this is invalid, as the default values should be specified from right to left.

Therefore, the answer is: a, c.

 Which of the following function declarations with default arguments are correct? Select one or more. void g(int length, int width, int height = 1); void g(int

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site