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

Discussion

Which of the following structure declarations will throw an error?

  • A.struct temp{}s; main(){}
  • B.struct temp{}; struct temp s; main(){}
  • C.struct temp s; struct temp{}; main(){}
  • D.None of the mentioned

Answer: D

Correct answer: struct temp s; struct temp{}; main(){}

This one is an error. Declaring struct temp s; before the structure has been defined means declaring an object of an incomplete type - the compiler does not yet know how much storage to reserve. The other two are fine: the first defines the type and a variable together, and the second defines the type before using it. (A pointer to an incomplete type would be legal, since a pointer’s size is known.)

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

Post your comment

Please log in or register to post a comment.