Ask Question
8 April, 04:20

Suppose that I have the following function declaration:

struct x_struct my_function (struct x_struct val);

While this is legal, it suffers from an inefficiency. What is the problem?

a.

I have no idea. This is not the answer ...

b.

The function will execute slowly because "val", and the return value of the function will both require a lot of data copying. This is because C is call-by-value.

c.

The function can not alter the original value of "val", so passing it is not useful.

d.

The function can alter the original structure "val", making the code hard to follow.

e.

The function will execute slowly because "val", and the return value of the function will both require a lot of data copying. This is because C is call-by-reference.

+5
Answers (1)
  1. 8 April, 04:33
    0
    b. The function will execute slowly because "val", and the return value of the function will both require a lot of data copying. This is because C is call-by-value.

    Explanation:

    Given Function signature: struct x_struct my_function (struct x_struct val);

    The function my_function takes a structure of type struct x_struct as arguments and returns a structure of the same type.

    C make use of call by value. So it will involve a copy of the struct argument and the return value as part of function execution. This will slow down the speed of execution particularly if the size of the structure is large. So option b is the correct option.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Suppose that I have the following function declaration: struct x_struct my_function (struct x_struct val); While this is legal, it suffers ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers