Typedef in C Programming MCQ Questions and Answers

1. Which of the following best describes the purpose of typedef in C?
A) To allocate memory dynamically
B) To create an alias for an existing data type
C) To define a constant variable
D) To include a header file
Answer: B

2. Which of the following is the correct syntax for creating a new name for an existing data type using typedef?
A) typedef int number;
B) typedef int number;
C) int typedef number;
D) define int number;
Answer: B

3. What will be the effect of the following code?
typedef unsigned long ulong;
A) Creates a macro for unsigned long
B) Defines ulong as an alias for unsigned long
C) Creates a new unsigned type
D) Declares a variable named ulong
Answer: B

4. Which of the following is NOT a valid use of typedef?
A) Creating type aliases for structures
B) Creating type aliases for pointers
C) Defining macros for constants
D) Simplifying complex data types
Answer: C

5. Consider the following code:
typedef int* intptr;
intptr p1, p2;
What is the type of p1 and p2?
A) int
B) Both are pointers to int
C) int and int* respectively
D) int**
Answer: B

6. typedef in C is mainly used to:
A) Increase execution speed
B) Reduce memory consumption
C) Improve code readability and maintainability
D) Implement recursion
Answer: C

7. Which of the following statements is true regarding typedef?
A) It allocates storage for a new data type
B) It defines a structure only
C) It only renames existing data types without creating new ones
D) It is equivalent to #define
Answer: C

8. What is the output of the following C code?
typedef int NUMBER;
NUMBER x = 5;
printf(“%d”, x);
A) Compiler error
B) 5
C) Garbage value
D) Depends on compiler
Answer: B

9. Which is the correct use of typedef for defining a function pointer?
A) typedef int func(int, int);
*B) typedef int (funcptr)(int, int);
C) typedef int funcptr(int, int);
D) define int (*funcptr)(int, int);
Answer: B

10. Which of the following pairs of declarations are equivalent?
A) typedef char* string; and #define string char*
B) Both behave identically in all cases
C) They differ in pointer declaration behavior
D) None of these
Answer: C

11. Which of the following statements about typedef and #define is TRUE?
A) Both work during runtime
B) Both create new variables
C) typedef is processed by the compiler, whereas #define is processed by the preprocessor
D) typedef cannot be used for structures
Answer: C

12. What is the output of the following program?
typedef float real;
real x = 2.5;
printf(“%.1f”, x);
A) 0.0
B) Compilation error
C) 2.5
D) Garbage value
Answer: C

13. Which of the following is TRUE about typedef usage with struct?
A) It prevents the use of structures
B) It creates a new structure type
C) It allows defining structure aliases without writing struct repeatedly
D) It automatically initializes members
Answer: C

14. Consider the code:
typedef struct {
int x, y;
} Point;
What is the type of Point?
A) A function type
B) A user-defined structure type alias
C) A pointer type
D) A macro expansion
Answer: B

15. Which is the correct declaration to define an alias byte for unsigned char?
A) typedef char byte;
B) typedef unsigned byte char;
C) typedef unsigned char byte;
D) #define unsigned char byte
Answer: C

16. What will happen if you declare two identical typedef statements in the same scope?
A) Compiler error
B) Runtime error
C) No error; they are treated as same alias
D) Undefined behavior
Answer: C

17. Which of the following can typedef NOT rename?
A) Enum
B) Pointer
C) Structure
D) Variable
Answer: D

18. In which section of memory does a typedef definition exist?
A) Stack
B) Heap
C) Symbol table (compile-time)
D) Static memory
Answer: C

19. Which of the following is valid typedef syntax?
A) typedef int [10] arr;
B) typedef int (arr)[10];
C) typedef int arr[10];
D) typedef [10]int arr;
Answer: C

20. Using typedef, you can:
A) Create dynamic types
B) Execute macros faster
C) Simplify complex pointer declarations
D) Avoid all type casting
Answer: C

21. Which of the following is a correct alias for a structure pointer?
struct Node { int data; struct Node* next; };
A) typedef struct Node list;
B) typedef struct Node NodePtr;*
C) typedef Node* struct Node;
D) #define NodePtr struct Node*
Answer: B

22. Which of these is most appropriate for naming an alias for a function pointer?
A) typedef void (*FP)(int);
*B) typedef void (FuncPtr)(int);
C) typedef void (int)*FuncPtr;
D) #define FuncPtr void (*)(int)
Answer: B

23. Can typedef be used inside a function body?
A) No
B) Yes, within local scope
C) Only for global variables
D) Only for arrays
Answer: B

24. In C, typedef can be combined with:
A) register
B) auto
C) struct, enum, and union
D) inline functions
Answer: C

25. Which is the correct alias for a function returning float and taking two int parameters?
A) typedef float func(int, int);
*B) typedef float (operation)(int, int);
C) typedef operation(float, int, int);
D) typedef func(*float)(int, int);
Answer: B

26. The keyword typedef stands for:
A) Type-definer
B) Type-definition file
C) Type definition
D) Type default
Answer: C

27. What is the effect of typedef const int ci;?
A) Declares an integer variable
B) Declares a function
C) Defines ci as alias for constant integer type
D) Allocates memory
Answer: C

28. What will happen in this code?
typedef int ARRAY[5];
ARRAY a = {1, 2, 3, 4, 5};
printf(“%d”, a[2]);
A) Compiler error
B) 1
C) 3
D) Undefined
Answer: C

29. Which is the correct alias for an array of 10 char?
A) typedef char arr(10);
B) typedef char arr[10];
C) typedef arr char[10];
D) define char arr[10];
Answer: B

30. Which of these statements is true for typedef?
A) It consumes runtime memory
B) It can define functions
C) It does not create a new type but an alias
D) It modifies variable storage
Answer: C

31. Can we use typedef for struct without naming the structure?
A) No
B) Yes, by using anonymous struct
C) Only with pointer
D) Only in global scope
Answer: B

32. What is the output of the following code?
typedef int INTEGER;
INTEGER a = 4;
printf(“%d”, sizeof(a));
A) 2
B) 8
C) 4
D) Undefined
Answer: C

33. Which one is valid?
A) typedef float real, *rptr;
B) real x; rptr y;
C) Both A and B
D) Neither
Answer: C

34. What is typedef struct { int id; char name[20]; } Student; doing?
A) Declares a structure variable
B) Creates a new structure type alias named Student
C) Creates a union
D) None
Answer: B

35. Which of the following improves type safety using typedef?
A) typedef int integer;
B) typedef struct { int x, y; } Point;
C) typedef char* string;
D) typedef long int number;
Answer: B

36. When is typedef evaluated?
A) During linking
B) During runtime
C) During compilation
D) During preprocessing
Answer: C

37. Which of the following is a valid combination?
A) typedef enum {A, B} Letters;
B) typedef enum {A, B} Letters;
C) enum typedef Letters {A, B};
D) #typedef enum {A, B} Letters;
Answer: B

38. Which is more appropriate for defining boolean values in C using typedef?
A) typedef char bool;
B) typedef enum { false, true } bool;
C) typedef int bool;
D) typedef bool _Bool;
Answer: B

39. Can we use typedef in header files?
A) No
B) Yes, it is commonly done for portability
C) Only with static variables
D) Only in main.c
Answer: B

40. What is the advantage of using typedef with struct in large projects?
A) Reduces CPU time
B) Makes linking faster
C) Improves code readability and maintainability
D) Increases compilation speed
Answer: C

41. Can typedef be used to rename a pointer to a function returning void?
A) No
B) Yes, by using parentheses with * operator
C) Only inside structures
D) Only if function is inline
Answer: B

42. What is the main difference between typedef and #define?
A) typedef is slower
B) typedef works only in C++
C) typedef is type-safe; #define is text substitution
D) They behave identically
Answer: C

43. Which of these statements about typedef is false?
A) It increases code readability
B) It allocates memory for types
C) It can be used for arrays
D) It can be used for pointers
Answer: B

44. Identify the correct statement:
A) typedef modifies storage class
B) typedef defines macros
C) typedef defines type aliases only
D) typedef changes variable scope
Answer: C

45. In C, typedef can be used to:
A) Create dynamic data types
B) Allocate heap memory
C) Rename existing data types
D) Define constants
Answer: C

46. Which of the following is correct for a structure alias?
typedef struct Book {
int id;
char name[20];
} Book;
A) struct Book b;
B) struct b;
C) Book b;
D) typedef b;
Answer: C

47. Which of these is true for nested typedefs?
A) Not allowed
B) Generates error
C) Allowed and used to simplify complex declarations
D) Requires macros
Answer: C

48. In C, what happens if typedef is used twice for the same alias but for different types?
A) Allowed silently
B) Runtime warning
C) Compiler error
D) Undefined behavior
Answer: C

49. Which of these keywords can be used with typedef?
A) static
B) extern
C) struct / union / enum
D) inline
Answer: C

50. Which of the following typedef usage is valid?
A) typedef int 10number;
B) typedef int number10;
C) typedef number int;
D) typedef int.number;
Answer: B

51. Which statement is true about typedef and storage class?
A) It affects storage class
B) It does not affect storage class
C) It defines static variables
D) It converts local to global
Answer: B

52. What does typedef char* string; do?
A) Declares a string variable
B) Creates alias string for char*
C) Defines a new data type
D) Declares an array of characters
Answer: B

53. Which of the following is a correct typedef for a pointer to a float?
A) typedef float& ptr;
B) typedef *float ptr;
C) typedef float ptr;*
D) typedef pointer float;
Answer: C

54. What is a limitation of typedef compared to #define?
A) Slower
B) Cannot be used for numeric constants
C) Consumes memory
D) Works only in C++
Answer: B

55. In C, typedef definitions are visible:
A) Only in the current line
B) In all files by default
C) Within the same scope where defined
D) Until program terminates
Answer: C

56. Which of these is correct for declaring a pointer to function returning int?
A) typedef int func*();
B) typedef *int func();
*C) typedef int (funcptr)(void);
D) typedef int funcptr*();
Answer: C

57. Which of the following best describes typedef behavior?
A) Executes at runtime
B) Converts code to inline
C) Performs compile-time aliasing
D) Allocates stack space
Answer: C

58. Which of the following code uses typedef for defining an alias for unsigned int correctly?
A) typedef unsigned integer int;
B) typedef unsigned int uint;
C) typedef uint unsigned int;
D) typedef int unsigned;
Answer: B

59. What is the correct typedef for a function taking char* and returning int?
A) typedef char* intfunc();
B) typedef int (charfunc)(char);
C) typedef int charfunc(char*);
D) typedef charfunc int(*)(char*);
Answer: B

60. Which is true about typedef and const?
A) typedef const not allowed
B) They cannot appear together
C) typedef const int ci; makes ci an alias for constant int type
D) It removes constness
Answer: C

61. What is the output of the following code?
typedef int arr[3];
arr a = {10, 20, 30};
printf(“%d”, a[1]);
A) 10
B) 20
C) 30
D) Compiler error
Answer: B

62. Why is typedef useful in pointer declarations?
A) It reduces type safety
B) It makes code slower
C) It simplifies multiple pointer declarations
D) It replaces malloc()
Answer: C

63. Which of these allows defining aliases for bit fields?
A) Not possible
B) Yes, through structure typedefs
C) Only in C++
D) Using macros only
Answer: B

64. The keyword typedef is evaluated by:
A) Linker
B) Loader
C) Compiler
D) Assembler
Answer: C

65. Can typedef be applied to arrays of structures?
A) No
B) Yes, it is allowed
C) Only globally
D) Only in C++
Answer: B

66. What will happen if you write this code?
typedef int data;
data x = 10;
printf(“%d”, x);
A) Error
B) Prints 10
C) Undefined behavior
D) No output
Answer: B

67. Which of these is the main difference between typedef and #define for pointers?
A) Both are same
B) No difference
C) typedef applies to whole type; #define can misinterpret pointer grouping
D) #define is more type-safe
Answer: C

68. Which statement about typedef scope is correct?
A) Global only
B) File scope only
C) Follows same scope as variable definitions
D) Works only in headers
Answer: C

69. What is the main purpose of typedef in large projects?
A) Increase performance
B) Increase abstraction and portability
C) Reduce code size
D) Manage heap memory
Answer: B

70. Which of the following defines a type for a pointer to an array of 5 integers?
A) typedef int (*ptr)[5];
*B) typedef int (ptr)[5];
C) typedef int ptr[5];
D) typedef int *ptr[5];
Answer: B

71. Which typedef simplifies defining linked list nodes?
A) typedef struct node Node;
B) typedef struct node { int data; struct node next; } Node;*
C) typedef struct node *Node;
D) None
Answer: B

72. Which of these cannot be aliased using typedef?
A) Structure
B) Enum
C) Macro constant
D) Pointer
Answer: C

73. The output of this code is?
typedef int arr[4];
arr a = {1, 2, 3, 4};
printf(“%d”, a[3]);
A) 1
B) 2
C) 3
D) 4
Answer: D

74. Which is correct for declaring an alias for a function returning void and taking no parameters?
A) typedef void (*func)();
*B) typedef void (functype)(void);
C) typedef void functype();
D) typedef functype void();
Answer: B

75. Why is typedef often used with hardware-level C programming?
A) To optimize speed
B) To ensure platform-independent data types
C) To improve debugging
D) To reduce binary size
Answer: B

76. typedef can help when dealing with:
A) Large loops
B) Platform-dependent data width
C) Inline macros
D) External linkage
Answer: B

77. Which typedef correctly defines a type for a pointer to a function returning char and taking int?
A) typedef (*ptr)(int) char;
B) typedef char ptr(int*);
*C) typedef char (ptr)(int);
D) typedef char ptr*();
Answer: C

78. What does the following code mean?
typedef int matrix[3][3];
A) Defines a structure
B) Defines alias matrix as 3×3 integer array
C) Declares variable
D) Defines a pointer
Answer: B

79. Can typedef be used inside a struct definition?
A) No
B) Yes
C) Only globally
D) Only in C++
Answer: B

80. Which is valid for defining alias of union type?
A) typedef union type alias;
B) typedef union { int a; float b; } Data;
C) typedef union (int a, float b) Data;
D) union typedef Data;
Answer: B

81. What is typedef void (*callback)(int); used for?
A) Defines macro
B) Defines alias for pointer to callback function taking int
C) Defines struct
D) Declares variable
Answer: B

82. Which of the following is correct about typedef portability?
A) Platform dependent
B) Slows code
C) Helps maintain same type sizes across systems
D) Affects assembly output
Answer: C

83. Can typedefs be declared in header files?
A) No
B) Yes, usually to share common types
C) Only one per file
D) Only static typedefs
Answer: B

84. Which of the following creates an alias for a pointer to a struct?
A) typedef struct Node Node;
B) typedef struct Node NodePtr;*
C) typedef Node struct*;
D) #define NodePtr struct Node
Answer: B

85. Why is typedef preferred for abstract data types (ADTs)?
A) To reduce binary size
B) To hide implementation details from users
C) To reduce runtime memory
D) To replace preprocessor
Answer: B

86. Which of these statements is correct?
A) typedef cannot alias function types
B) typedef can alias both function and pointer types
C) typedef only for primitives
D) typedef creates macros
Answer: B

87. What is the output?
typedef int num;
num x = 3, y = 4;
printf(“%d”, x + y);
A) 3
B) 4
C) 7
D) Error
Answer: C

88. What is the primary benefit of typedef with structures?
A) Creates new memory model
B) Increases execution time
C) Reduces verbosity in type names
D) Enables dynamic linking
Answer: C

89. When using typedef, which naming convention is recommended in C?
A) ALL CAPS
B) PascalCase or CamelCase for clarity
C) lowercase only
D) No standard exists
Answer: B

90. Which is true for typedef aliases across files?
A) Need no inclusion
B) Must be declared in header file for reuse
C) Automatically imported
D) Work across all source files
Answer: B

91. What is the function of typedef struct Node Node;?
A) Creates a structure variable
B) Creates an alias for structure type
C) Allocates memory
D) Declares a pointer
Answer: B

92. Which typedef is best used for defining custom boolean?
A) typedef _Bool BOOL;
B) typedef char bool;
C) typedef enum { FALSE, TRUE } BOOL;
D) typedef int Boolean;
Answer: C

93. What is typedef int (*Compare)(int, int);?
A) Function prototype
B) Alias for pointer to comparison function
C) Macro
D) Structure
Answer: B

94. What is typedef often used for in APIs?
A) Reduce execution
B) Abstract data types and platform independence
C) Allocate heap memory
D) Generate headers automatically
Answer: B

95. Which of the following is valid alias for 64-bit integer?
A) typedef long int int64;
B) typedef long long int int64;
C) typedef int longlong;
D) typedef integer long long;
Answer: B

96. Can typedef be used for recursive structures?
A) No
B) Yes, via self-referencing pointers
C) Only in C++
D) Needs templates
Answer: B

97. What happens if you declare a variable before typedef?
A) Runtime error
B) Variable unaffected; typedef independent
C) Variable renamed
D) Compilation stops
Answer: B

98. The correct typedef for pointer to constant integer is:
A) typedef int *const ptr;
B) typedef const int ptr;*
C) typedef const ptr int*;
D) typedef const int ptr*;
Answer: B

99. Why is typedef important in embedded C?
A) Makes code hardware-specific
B) Allows portability across processors
C) Increases binary size
D) Removes pointer usage
Answer: B

100. Which of these best defines the typedef keyword?
A) Runtime type initializer
B) Type allocator
C) Type alias specifier at compile-time
D) Structure preprocessor
Answer: C