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

Discussion

Assertion (A) : char str[] = "paper"
'str' acts as a constant pointer to a string.

Reason (R) : *P = "Paper"
"P" acts as a pointer to a constant string.

  • A.Both (A) and (R) are true and (R) is the correct explanation of (A).
  • B.Both (A) and (R) are true, but (R) is not the correct explanation of (A).
  • C.(A) is true, but (R) is false.
  • D.(A) is false, but (R) is true.

Answer: B

Both statements are true but the reason does not explain the assertion, which is option (B). In char str[] = "paper" the name str is the address of the first element of the array and cannot be changed, so it behaves as a constant pointer to the string. In the reason, P is a pointer that is made to point at a string constant, so it is a pointer to a constant string. The two describe different declarations, so one does not explain the other, which rules out (A), and neither statement is false, which rules out (C) and (D).

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

Post your comment

Please log in or register to post a comment.