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

Discussion

Which of the following statements mentioning the name of the array does NOT yield the base address?

1. When array name is used with the sizeof operator.

2. When array name is operand of the & operator.

3. When array name is passed to scanf() function.

4. When array name is passed to printf() function.

  • A.1
  • B.1, 2
  • C.2
  • D.2, 4

Answer: B

Correct answer: 1, 2

The name of an array normally decays to the address of its first element - which is why passing it to scanf() or printf() gives the base address. There are two exceptions. With sizeof the name means the whole array, so sizeof(arr) gives the total number of bytes. With & it again means the whole array, so &arr has type “pointer to array”. Those are statements 1 and 2.

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

Post your comment

Please log in or register to post a comment.