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

Discussion

For the following expression to work, which option should be selected.
string p = “HELLO”;

  • A.typedef char [] string;
  • B.typedef char * string;
  • C.Both (a) and (b)
  • D.Such expression cannot be generated in C

Answer: B

Correct answer: typedef char * string;

The alias must be a pointer type, because a string literal in an expression yields the address of its first character. With typedef char *string; in place, string p = "HELLO"; simply stores that address. An array alias will not serve: an array type cannot be assigned to, and an unsized one is incomplete.

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

Post your comment

Please log in or register to post a comment.