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

Discussion

Which option should be selected to work the following C expression?

string p = "HELLO";

 

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

Answer: B

Correct answer: typedef char *string;

A string in C is a pointer to its first character, so the alias must be a pointer type: typedef char *string; lets string p = "HELLO"; assign the literal’s address to p. The array form is not merely wrong syntax - even typedef char string[]; would give an incomplete type that cannot be initialised this way.

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

Post your comment

Please log in or register to post a comment.