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

Discussion

What is the essential difference between typedef and a #define macro for naming a type ?

  • A.There is no difference
  • B.typedef is handled by the compiler and respects scope, while #define is a textual substitution by the preprocessor
  • C.typedef works only for structures
  • D.#define is checked for type correctness but typedef is not

Answer: C

Correct answer: typedef is handled by the compiler and respects scope, while #define is a textual substitution by the preprocessor

Because typedef is part of the language proper it obeys the usual scoping rules and handles complex declarations correctly. A macro merely pastes text, which is why a #define for a pointer type applies the star to only the first name in a multiple declaration.

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

Post your comment

Please log in or register to post a comment.