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

Discussion

Which of the following are correct syntaxes to send an array as a parameter to function:

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

Answer: B

Correct answer: func(array);

An array name in an expression decays to a pointer to its first element, so passing the name is all that is required and the function receives that pointer. &array gives a pointer to the whole array, a different type; *array passes the first element rather than the array; and array[size] passes one element, and one that is out of bounds at that.

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

Post your comment

Please log in or register to post a comment.