C- Typedef Questions and Answers

Practice Mode
Showing 10 of 23 questions
Q11
What happens when we use typedef with a structure without a tag?
  • A Compiler error
  • B Creates type alias for anonymous structure
  • C Creates global variable
  • D Nothing happens
Answer: Option B
Explanation: Creates type alias for anonymous structure
Q12
Which scope does typedef follow?
  • A Global scope only
  • B File scope only
  • C Follows normal C scope rules
  • D Function scope only
Answer: Option C
Explanation: typedef follows normal C scope rules
Q13
What is the difference between typedef and #define?
  • A No difference
  • B typedef is for constants, #define for types
  • C typedef is interpreted by compiler, #define by preprocessor
  • D #define is more powerful
Answer: Option C
Explanation: typedef is interpreted by compiler, #define by preprocessor
Q14
Can typedef be used to create a new data type?
  • A Yes, always
  • B No, it only creates aliases
  • C Only with structures
  • D Only with pointers
Answer: Option B
Explanation: No, typedef only creates aliases for existing types
Q15
How to use typedef with enum?
  • A typedef enum {RED, BLUE} Colors;
  • B enum typedef Colors {RED, BLUE};
  • C typedef {RED, BLUE} Colors;
  • D enum Colors typedef {RED, BLUE};
Answer: Option A
Explanation: Similar to structures, typedef can simplify enum usage
Q16
What is the output of: typedef int Integer; Integer x = 5; printf("%d", x);
  • A 0
  • B 5
  • C Garbage value
  • D Compiler error
Answer: Option B
Explanation: Integer is alias for int, so output is 5
Q17
Which is better for type checking: typedef or #define?
  • A Both are same
  • B typedef provides better type checking
  • C #define provides better type checking
  • D Neither provides type checking
Answer: Option B
Explanation: typedef provides better type checking
Q18
Can we use typedef inside a function?
  • A No, typedef is always global
  • B Yes, typedef can have local scope
  • C Only in main function
  • D Only with primitive types
Answer: Option B
Explanation: Yes, typedef can have local scope
Q19
What does typedef unsigned int UINT; do?
  • A Declares UINT variable
  • B Creates UINT as alias for unsigned int
  • C Defines UINT constant
  • D Includes UINT header
Answer: Option B
Explanation: Creates UINT as alias for unsigned int
Q20
How to declare multiple typedefs in one statement?
  • A typedef int a, b, c;
  • B typedef int a; typedef int b; typedef int c;
  • C typedef int a, b, c; is invalid
  • D typedef (int a, int b, int c);
Answer: Option B
Explanation: Multiple typedefs need separate statements
Questions and Answers for Competitive Exams Various Entrance Test