Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following is the correct syntax to send an array as a parameter to function?

  • A.func(&array);
  • B.func(#array);
  • C.func(*array);
  • D.func(array[size]);

Answer: A

Correct answer: func(&array);

Of the four forms offered this is the only valid C that passes the array's address. &array yields a pointer to the whole array, which the function can receive as int (*)[N].

It is worth noting that the idiomatic form, func(array), is not among the options: an array name in an expression decays to a pointer to its first element, so writing the bare name already passes the address. The other options are not valid syntax at all, or pass a single element rather than the array.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.