5.2 - Structures.


Back Button Home

5.2.1 - Overview of Structures.


1. What is a structure in C?
  • (A) A data type that holds a single value
  • (B) A user-defined data type that can hold multiple values of different types
  • (C) A reserved keyword
  • (D) A collection of functions
Correct Answer: (B) A user-defined data type that can hold multiple values of different types
2. Which keyword is used to define a structure in C?
  • (A) struct
  • (B) union
  • (C) enum
  • (D) class
Correct Answer: (A) struct
3. How do you access members of a structure?
  • (A) Using the * operator
  • (B) Using the . operator and -> operator
  • (C) Using the & operator
  • (D) Using the | operator
Correct Answer: (B) Using the . operator and -> operator
4. What does the following code declare?
            struct stud {
                char name[80];
                int roll;
                float mark;
            };
                
  • (A) A structure with members of the same type
  • (B) A union
  • (C) A structure with three different members
  • (D) An enumeration
Correct Answer: (C) A structure with three different members
5. What will be the output of this code?
            struct stud {
                char name[80];
                int roll;
                float mark;
            } st;
            
            st.roll = 100;
            printf("%d", st.roll);
                
  • (A) 0
  • (B) 100
  • (C) Garbage value
  • (D) Compilation error
Correct Answer: (B) 100
6. How can you define a structure variable without giving it a name?
  • (A) struct stud st;
  • (B) struct { char name[80]; int roll; } st;
  • (C) struct stud;
  • (D) struct stud {};
Correct Answer: (B) struct { char name[80]; int roll; } st;
7. What does the sizeof operator return when used with a structure?
  • (A) The size of the first member
  • (B) The size of the entire structure
  • (C) The size of the pointer to the structure
  • (D) The size of each member
Correct Answer: (B) The size of the entire structure
8. Which of the following correctly defines a function that takes a structure as an argument?
  • (A) void printStud(struct stud s);
  • (B) void printStud(struct *s);
  • (C) void printStud(struct stud *s);
  • (D) Both A and C
Correct Answer: (D) Both A and C
9. What will happen if you try to access a member of a structure through a null pointer?
  • (A) The program will work correctly
  • (B) It will cause a segmentation fault
  • (C) It will print a random value
  • (D) It will result in a compile-time error
Correct Answer: (B) It will cause a segmentation fault
10. How do you return a structure from a function?
  • (A) By passing a pointer to the structure
  • (B) By returning the structure directly
  • (C) Both A and B
  • (D) You cannot return a structure from a function
Correct Answer: (C) Both A and B
11. Which operator is used to access structure members through a pointer?
  • (A) . (dot)
  • (B) * (dereference)
  • (C) -> (arrow)
  • (D) & (address)
Correct Answer: (C) -> (arrow)
12. What is the output of the following code?
            struct Point {
                int x;
                int y;
            };
            
            struct Point p = {3, 4};
            printf("%d", p.x);
                
  • (A) 4
  • (B) 3
  • (C) 0
  • (D) Compilation error
Correct Answer: (B) 3
13. What type of variable is created when defining a structure without a name?
  • (A) A global variable
  • (B) A local variable
  • (C) An unnamed structure variable
  • (D) A pointer variable
Correct Answer: (C) An unnamed structure variable
14. What is the primary use of using structures in C?
  • (A) To group related data
  • (B) To create dynamic memory
  • (C) To perform mathematical calculations
  • (D) To create an infinite loop
Correct Answer: (A) To group related data
15. How can you initialize a structure in C?
  • (A) By assigning values directly
  • (B) Using a constructor
  • (C) Through a function only
  • (D) You cannot initialize a structure
Correct Answer: (A) By assigning values directly
16. What will be the output of this code?
            struct stud {
                char name[80];
                int roll;
                float mark;
            } s1 = {"John", 101, 85.5};
            
            printf("%s", s1.name);
                
  • (A) 0
  • (B) John
  • (C) Compilation error
  • (D) It will print garbage value
Correct Answer: (B) John
17. Which of the following can be a member of a structure?
  • (A) int, float, char arrays
  • (B) another structure
  • (C) pointers
  • (D) All of the above
Correct Answer: (D) All of the above
18. Which statement is true regarding unions and structures?
  • (A) Unions use more memory than structures
  • (B) Structures can hold different types of data, while unions hold one type
  • (C) Structures can only hold integers
  • (D) Unions can have only one member
Correct Answer: (B) Structures can hold different types of data, while unions hold one type
19. How do you define a structure with a member that is another structure?
  • (A) struct outer { struct inner; };
  • (B) struct outer { struct inner innerStruct; };
  • (C) struct outer { struct inner(); };
  • (D) struct outer { inner; };
Correct Answer: (B) struct outer { struct inner innerStruct; };
20. What is the default access specifier for structure members in C?
  • (A) public
  • (B) private
  • (C) protected
  • (D) There are no access specifiers in C
Correct Answer: (D) There are no access specifiers in C

5.2.2 - Arrays vs Structures.


21. What is an array in C?

  • (A) A collection of elements of the same data type
  • (B) A collection of elements of different data types
  • (C) A single variable that holds one value
  • (D) A reserved keyword
Correct Answer: (A) A collection of elements of the same data type

22. What is a structure in C?

  • (A) A collection of elements of the same data type
  • (B) A collection of elements of different data types
  • (C) A single variable that holds one value
  • (D) A reserved keyword
Correct Answer: (B) A collection of elements of different data types

23. How do you access an array element?

  • (A) Using the . operator
  • (B) Using the -> operator
  • (C) Using the [] operator
  • (D) Using the & operator
Correct Answer: (C) Using the [] operator

24. How do you access a structure member?

  • (A) Using the [] operator
  • (B) Using the . operator or -> operator
  • (C) Using the & operator
  • (D) Using the * operator
Correct Answer: (B) Using the . operator or -> operator

25. Can an array hold elements of different data types?

  • (A) Yes
  • (B) No
  • (C) Only if the elements are pointers
  • (D) Only in a structure
Correct Answer: (B) No

26. Can a structure hold an array as a member?

  • (A) Yes
  • (B) No
  • (C) Only if the array is of fixed size
  • (D) Only if the structure is dynamic
Correct Answer: (A) Yes

27. What is the default size of an array in C?

  • (A) 1
  • (B) 10
  • (C) Depends on the type of data stored
  • (D) There is no default size
Correct Answer: (D) There is no default size

28. How do you declare a structure that includes an array?

  • (A) struct { int arr[10]; } myStruct;
  • (B) struct myStruct { int arr[]; };
  • (C) struct myStruct { int arr; };
  • (D) struct myStruct { int arr[10]; };
Correct Answer: (D) struct myStruct { int arr[10]; };

29. What happens if you access an out-of-bounds index in an array?

  • (A) It will cause a compile-time error
  • (B) It will print garbage value
  • (C) It will crash the program
  • (D) The program will work correctly
Correct Answer: (B) It will print garbage value

30. What happens if you access a member of a structure that is not initialized?

  • (A) It will print a default value
  • (B) It will print garbage value
  • (C) It will cause a segmentation fault
  • (D) It will cause a compile-time error
Correct Answer: (B) It will print garbage value

31. How do you define an array of structures?

  • (A) struct stud arr[10];
  • (B) struct stud *arr;
  • (C) struct { struct stud arr[10]; }
  • (D) struct arr[10] { stud; };
Correct Answer: (A) struct stud arr[10];

32. Which of the following can be members of a structure?

  • (A) Another structure
  • (B) Arrays
  • (C) Pointers
  • (D) All of the above
Correct Answer: (D) All of the above

33. How do you initialize an array of integers with 5 elements?

  • (A) int arr[5] = {1, 2, 3, 4, 5};
  • (B) int arr = {1, 2, 3, 4, 5};
  • (C) int arr[5] = (1, 2, 3, 4, 5);
  • (D) int arr[5]; arr = {1, 2, 3, 4, 5};
Correct Answer: (A) int arr[5] = {1, 2, 3, 4, 5};

34. Can a structure contain another structure?

  • (A) Yes
  • (B) No
  • (C) Only if it’s a pointer to another structure
  • (D) Only in dynamic memory
Correct Answer: (A) Yes

35. Which has a fixed size: array or structure?

  • (A) Array
  • (B) Structure
  • (C) Both have fixed sizes
  • (D) Neither have fixed sizes
Correct Answer: (A) Array

36. What is the size of a structure with two int members?

  • (A) 2 bytes
  • (B) 4 bytes
  • (C) 8 bytes
  • (D) Depends on the compiler and architecture
Correct Answer: (D) Depends on the compiler and architecture

37. What is the output of this code?

            struct stud {
                int roll;
                char name[20];
            } student = {101, "Alice"};
            
            printf("%d", student.roll);
                
  • (A) Alice
  • (B) 0
  • (C) 101
  • (D) Compilation error
Correct Answer: (C) 101

38. Can you use an array in a function as a parameter?

  • (A) Yes
  • (B) No
  • (C) Only if it’s a pointer
  • (D) Only if it’s a global array
Correct Answer: (A) Yes

39. How do you pass a structure to a function?

  • (A) By value
  • (B) By reference
  • (C) Both A and B
  • (D) You cannot pass a structure to a function
Correct Answer: (C) Both A and B

40. Which is more memory efficient for storing multiple related data of the same type?

  • (A) Structure
  • (B) Array
  • (C) Union
  • (D) Both have the same efficiency
Correct Answer: (B) Array

5.2.3 - Nested Structures.


41. What is a nested structure in C?

  • (A) A structure that contains an array
  • (B) A structure that contains another structure
  • (C) A structure with no members
  • (D) A structure that can be declared without a name
Correct Answer: (B) A structure that contains another structure

42. How do you access a member of a nested structure?

  • (A) Using the -> operator only
  • (B) Using the . operator twice
  • (C) Using the [] operator
  • (D) Using the & operator
Correct Answer: (B) Using the . operator twice

43. What is the purpose of using nested structures?

  • (A) To create arrays within structures
  • (B) To combine related data types into a single structure
  • (C) To avoid using functions
  • (D) To simplify variable names
Correct Answer: (B) To combine related data types into a single structure

44. How do you declare a nested structure?

  • (A) struct outer { struct inner { int a; }; };
  • (B) struct outer { int a; struct inner; };
  • (C) struct outer { struct inner { int a; }; inner b; };
  • (D) struct outer { struct inner; };
Correct Answer: (A) struct outer { struct inner { int a; }; };

45. What happens if you access a member of a nested structure that is not initialized?

  • (A) It prints a default value
  • (B) It prints garbage value
  • (C) It causes a segmentation fault
  • (D) It causes a compile-time error
Correct Answer: (B) It prints garbage value

46. Which operator is used to access members of a nested structure?

  • (A) []
  • (B) ->
  • (C) .
  • (D) &
Correct Answer: (C) .

47. Can a structure member itself be a nested structure?

  • (A) Yes
  • (B) No
  • (C) Only if it is an array
  • (D) Only if it is a pointer
Correct Answer: (A) Yes

48. How do you define a nested structure in a function?

  • (A) You cannot define nested structures in functions
  • (B) By using the same syntax as outside the function
  • (C) By using an array inside the structure
  • (D) By declaring the nested structure first
Correct Answer: (B) By using the same syntax as outside the function

49. How can you initialize a nested structure?

  • (A) struct outer o = {1, {2}};
  • (B) struct outer o = {1, 2};
  • (C) struct outer o; o.inner = 2;
  • (D) struct outer o; o.inner.a = 2;
Correct Answer: (A) struct outer o = {1, {2}};

50. In a nested structure, which keyword is used to define an inner structure?

  • (A) struct
  • (B) inner
  • (C) typedef
  • (D) union
Correct Answer: (A) struct

51. What is the output of the following code?

            struct emp {
                char name[50];
                struct dept {
                    int sal;
                    char degi[50];
                } d;
            };
            struct emp e = {"Alice", {50000, "Manager"}};
            printf("%s %d", e.name, e.d.sal);
                
  • (A) Alice 0
  • (B) Alice 50000
  • (C) 0 50000
  • (D) Manager Alice
Correct Answer: (B) Alice 50000

52. Can a structure contain a pointer to another structure?

  • (A) Yes
  • (B) No
  • (C) Only if it’s a nested structure
  • (D) Only in dynamic memory
Correct Answer: (A) Yes

53. What is the correct way to declare a variable of a nested structure?

  • (A) struct outer o;
  • (B) struct inner i;
  • (C) struct outer { struct inner; } o;
  • (D) struct inner o;
Correct Answer: (A) struct outer o;

54. What keyword is used to define a structure?

  • (A) class
  • (B) struct
  • (C) union
  • (D) typedef
Correct Answer: (B) struct

55. How do you access the designation of an employee in a nested structure?

  • (A) e.d.degi
  • (B) e->d.degi
  • (C) e.d->degi
  • (D) e->d->degi
Correct Answer: (A) e.d.degi

56. Which of the following statements is true about nested structures?

  • (A) They can only contain primitive data types
  • (B) They can contain arrays and other structures
  • (C) They cannot contain other structures
  • (D) They are not allowed in C
Correct Answer: (B) They can contain arrays and other structures

57. What is the size of a structure that contains two int members and one char member?

  • (A) 4 bytes
  • (B) 8 bytes
  • (C) 12 bytes
  • (D) Depends on the compiler and architecture
Correct Answer: (D) Depends on the compiler and architecture

58. How can you pass a nested structure to a function?

  • (A) By reference only
  • (B) By value only
  • (C) Both by reference and by value
  • (D) You cannot pass nested structures to functions
Correct Answer: (C) Both by reference and by value

59. How do you declare a structure with a nested structure and an array?

  • (A) struct outer { struct inner { int a; } b; int arr[10]; };
  • (B) struct outer { struct inner b; int arr[10]; };
  • (C) struct outer { int arr[10]; struct inner; };
  • (D) Both A and B
Correct Answer: (D) Both A and B

60. Can you use a nested structure to represent a complex data type such as a student with courses?

  • (A) Yes
  • (B) No
  • (C) Only if you use arrays
  • (D) Only if the courses are defined as enums
Correct Answer: (A) Yes

5.2.4 - Array of Structures.


61. What is an array of structures in C?
  • (A) An array containing basic data types
  • (B) An array containing similar structure data types
  • (C) An array containing only one structure type
  • (D) An array containing dissimilar data types
Correct Answer: (B) An array containing similar structure data types
62. How do you declare an array of structures?
  • (A) struct name[size];
  • (B) struct name[];
  • (C) struct name variable[size];
  • (D) struct name variable;
Correct Answer: (C) struct name variable[size];
63. Which of the following is true about the members of a structure?
  • (A) All members must be of the same data type
  • (B) Members can be of different data types
  • (C) Members cannot be arrays
  • (D) Members must be initialized at declaration
Correct Answer: (B) Members can be of different data types
64. What is the output of the following code snippet?
     struct student {
         char name[20];
         int roll;
     };
     struct student s[2] = {{"Alice", 1}, {"Bob", 2}};
     printf("%s", s[0].name);
                
  • (A) Bob
  • (B) Alice
  • (C) 1
  • (D) 2
Correct Answer: (B) Alice
65. What does the fflush(stdin) function do in the context of input?
  • (A) It clears the entire console
  • (B) It clears the input buffer
  • (C) It flushes the output buffer
  • (D) It is not a standard function
Correct Answer: (B) It clears the input buffer
66. What is the purpose of passing structures to functions?
  • (A) To modify global variables
  • (B) To enable access to structure members
  • (C) To create a new structure
  • (D) To create local copies of structure data
Correct Answer: (B) To enable access to structure members
67. How can you pass a structure to a function by reference?
  • (A) By using the address of the structure
  • (B) By using the structure variable directly
  • (C) By using a pointer to the structure
  • (D) Both A and C
Correct Answer: (D) Both A and C
68. In the context of structures, what does getch() do?
  • (A) Reads a character from the standard input
  • (B) Returns the next character from standard input
  • (C) Waits for a key press
  • (D) Both B and C
Correct Answer: (D) Both B and C
69. What will be the output of this code?
                struct stud {
                    char name[20];
                    int roll;
                };
                struct stud s = {"Alice", 1};
                printf("%d", s.roll);
                
  • (A) Alice
  • (B) 1
  • (C) Roll
  • (D) Name
Correct Answer: (B) 1
70. How do you access a member of a structure within an array?
  • (A) array[index].member
  • (B) array->member
  • (C) array.member[index]
  • (D) array[index]->member
Correct Answer: (A) array[index].member
71. Which of the following statements is true about structure members?
  • (A) They are stored in non-contiguous memory
  • (B) They can only be of one data type
  • (C) They can be public or private
  • (D) They are stored in contiguous memory locations
Correct Answer: (D) They are stored in contiguous memory locations
72. What happens if you try to access an uninitialized member of a structure?
  • (A) It will return 0
  • (B) It will cause a compilation error
  • (C) It will return garbage value
  • (D) It will return NULL
Correct Answer: (C) It will return garbage value
73. Can a structure contain another structure as a member?
  • (A) Yes
  • (B) No
  • (C) Only if the inner structure is an array
  • (D) Only if the outer structure is a pointer
Correct Answer: (A) Yes
74. Which of the following is a valid way to declare a structure variable?
  • (A) struct student s;
  • (B) struct student;
  • (C) student s;
  • (D) struct student s[];
Correct Answer: (A) struct student s;
75. What is a self-referential structure?
  • (A) A structure that contains an array of itself
  • (B) A structure that contains a pointer to itself
  • (C) A structure with no members
  • (D) A structure containing another structure
Correct Answer: (B) A structure that contains a pointer to itself
76. Which statement about structure members is correct?
  • (A) They can have private access
  • (B) They can be static
  • (C) They are public by default
  • (D) They cannot be accessed outside the structure
Correct Answer: (C) They are public by default
77. Which function is used to read a string from the standard input?
  • (A) scanf()
  • (B) gets()
  • (C) fgets()
  • (D) Both B and C
Correct Answer: (D) Both B and C
78. How do you display the entire content of an array of structures?
  • (A) By using a single printf statement
  • (B) By using a loop to access each member
  • (C) By using a pointer
  • (D) You cannot display arrays of structures
Correct Answer: (B) By using a loop to access each member
79. What happens when a structure is passed by value to a function?
  • (A) The original structure is modified
  • (B) A copy of the structure is created
  • (C) Memory is not allocated
  • (D) It causes a runtime error
Correct Answer: (B) A copy of the structure is created
80. Which of the following is an advantage of using structures?
  • (A) They increase the complexity of the code
  • (B) They allow grouping of related data
  • (C) They can only store one type of data
  • (D) They do not allow nesting
Correct Answer: (B) They allow grouping of related data

5.2.5 - Passing Structures as Arguments in Functions.


81. What happens when a structure variable is passed to a function in C?
  • (A) The original structure is modified
  • (B) A copy of the structure is passed to the function
  • (C) The function cannot access the structure
  • (D) It causes a compilation error
Correct Answer: (B) A copy of the structure is passed to the function
82. How do you define a structure in C?
  • (A) struct name{...};
  • (B) struct name;
  • (C) name struct{...};
  • (D) struct name[];
Correct Answer: (A) struct name{...};
83. In the given program, what is the type of the member "name" in the "student" structure?
  • (A) char
  • (B) char[]
  • (C) char *
  • (D) string
Correct Answer: (C) char *
84. What does the display() function do in the provided code?
  • (A) Modifies the structure members
  • (B) Displays the structure member values
  • (C) Returns a modified structure
  • (D) Accepts multiple structures
Correct Answer: (B) Displays the structure member values
85. Which operator is used to access the members of a structure?
  • (A) ->
  • (B) .
  • (C) *
  • (D) &
Correct Answer: (B) .
86. How can you ensure that a pointer to a character in a structure points to valid memory?
  • (A) By assigning a literal string
  • (B) By using dynamic memory allocation
  • (C) Both A and B
  • (D) It cannot be done
Correct Answer: (C) Both A and B
87. In the function call display(o);, what does o represent?
  • (A) A pointer to a structure
  • (B) The structure itself
  • (C) The address of the structure
  • (D) A function
Correct Answer: (B) The structure itself
88. What will be the output of the given program?
            struct student {
                char *name;
                int age;
                float per;
            };
            struct student o = {"RAM", 25, 75.5};
            display(o);
                
  • (A) Name: 25, Age: RAM, Percent: 75.5
  • (B) Name: RAM, Age: 25, Percent: 75.5
  • (C) Name: RAM, Age: 75.5, Percent: 25
  • (D) None of the above
Correct Answer: (B) Name: RAM, Age: 25, Percent: 75.5
89. What does the return 0; statement indicate in the main() function?
  • (A) The program has errors
  • (B) The program completed successfully
  • (C) The program is still running
  • (D) The program is terminating
Correct Answer: (B) The program completed successfully
90. If the structure is modified in the display() function, what happens to the original structure in the main() function?
  • (A) It is modified
  • (B) It remains unchanged
  • (C) It will cause a runtime error
  • (D) It will be deleted
Correct Answer: (B) It remains unchanged
91. What is the purpose of using a pointer for the "name" member in the structure?
  • (A) To save memory
  • (B) To allow dynamic allocation of memory
  • (C) To avoid copying large strings
  • (D) All of the above
Correct Answer: (D) All of the above
92. Which of the following statements is true about passing structures to functions?
  • (A) Structures are passed by reference by default
  • (B) Structures are passed by value by default
  • (C) Structures cannot be passed to functions
  • (D) Functions can only accept primitive data types
Correct Answer: (B) Structures are passed by value by default
93. Can a function return a structure in C?
  • (A) Yes
  • (B) No
  • (C) Only if it’s a pointer
  • (D) Only if the structure has less than 5 members
Correct Answer: (A) Yes
94. What is the output of the following code snippet?
            struct student {
                char *name;
                int age;
                float per;
            };
            struct student o = {"Alice", 22, 88.5};
            printf("%s", o.name);
                
  • (A) Alice
  • (B) 22
  • (C) 88.5
  • (D) None of the above
Correct Answer: (A) Alice
95. What will happen if you try to print an uninitialized pointer member in a structure?
  • (A) It will print NULL
  • (B) It will cause a segmentation fault
  • (C) It will print garbage value
  • (D) It will print an empty string
Correct Answer: (C) It will print garbage value
96. What does the printf() function do in the display() function?
  • (A) Reads input from the user
  • (B) Displays output to the console
  • (C) Allocates memory for the structure
  • (D) Returns a value from the function
Correct Answer: (B) Displays output to the console
97. How do you pass a structure to a function by reference?
  • (A) By using the structure variable
  • (B) By using a pointer to the structure
  • (C) By using the address of the structure
  • (D) Both B and C
Correct Answer: (D) Both B and C
98. Which of the following correctly defines a structure in C?
  • (A) struct name {int a; float b;};
  • (B) struct name(int a, float b);
  • (C) name struct {int a; float b;};
  • (D) struct name: {int a; float b;};
Correct Answer: (A) struct name {int a; float b;};
99. What is the effect of using void display(struct student o) instead of void display(struct student *o)?
  • (A) The original structure can be modified
  • (B) The original structure cannot be modified
  • (C) It will cause a compilation error
  • (D) It will cause a segmentation fault
Correct Answer: (B) The original structure cannot be modified
100. Which of the following is NOT a valid way to declare a structure variable?
  • (A) struct student o;
  • (B) struct student *o;
  • (C) struct student o[10];
  • (D) student o;
Correct Answer: (D) student o;

5.2.6 - Typedef.


101. What is the purpose of the typedef keyword in C?
  • (A) To create a new variable
  • (B) To provide existing data types with meaningful names
  • (C) To declare functions
  • (D) To allocate memory
Correct Answer: (B) To provide existing data types with meaningful names
102. How do you define a new alias for an existing data type using typedef?
  • (A) typedef alias_name existing_name;
  • (B) typedef existing_name alias_name;
  • (C) typedef existing_name as alias_name;
  • (D) alias_name typedef existing_name;
Correct Answer: (B) typedef existing_name alias_name;
103. Which of the following correctly defines an alias for unsigned int as unit?
  • (A) typedef unsigned int unit;
  • (B) typedef unit unsigned int;
  • (C) unsigned int typedef unit;
  • (D) unsigned int unit;
Correct Answer: (A) typedef unsigned int unit;
104. What is the output of the following code?
typedef struct {
                int x;
                int y;
            } point;
            point p = {10, 20};
            printf("%d %d", p.x, p.y);
  • (A) 10 20
  • (B) 0 0
  • (C) Compilation error
  • (D) 20 10
Correct Answer: (A) 10 20
105. What does typedef struct students { ... } stu; achieve?
  • (A) It creates a structure called students.
  • (B) It creates an alias stu for the structure students.
  • (C) It defines a function stu.
  • (D) It declares a variable stu.
Correct Answer: (B) It creates an alias stu for the structure students.
106. In the statement typedef int* ptr;, what does ptr represent?
  • (A) A function
  • (B) A data type
  • (C) A pointer to an integer
  • (D) An array of integers
Correct Answer: (C) A pointer to an integer
107. How can typedef improve code readability when using structures?
  • (A) By shortening the code
  • (B) By avoiding the use of struct repeatedly
  • (C) By changing the data type
  • (D) By defining functions
Correct Answer: (B) By avoiding the use of struct repeatedly
108. What is the output of the following code snippet?
typedef int Arr[4];
            Arr temp = {1, 2, 3, 4};
            printf("%d", temp[2]);
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4
Correct Answer: (C) 3
109. Which statement is true about typedef compared to #define?
  • (A) typedef can define constants, while #define cannot.
  • (B) typedef can create new types, while #define cannot.
  • (C) typedef requires a semicolon at the end, while #define does not.
  • (D) All of the above
Correct Answer: (D) All of the above
110. Which of the following is NOT a valid use of typedef?
  • (A) typedef int x;
  • (B) typedef int y[5];
  • (C) typedef struct { int a; } z;
  • (D) typedef #define MAX 100;
Correct Answer: (D) typedef #define MAX 100;
111. What is the main difference between typedef and #define?
  • (A) typedef is for defining constants, while #define is for data types.
  • (B) typedef defines data types, while #define defines constants.
  • (C) There is no difference; they are interchangeable.
  • (D) typedef requires arguments, while #define does not.
Correct Answer: (B) typedef defines data types, while #define defines constants.
112. How would you declare a pointer to a structure using typedef?
  • (A) typedef struct { ... } *ptr;
  • (B) typedef struct { ... } ptr;
  • (C) typedef struct { ... } &ptr;
  • (D) typedef struct *ptr;
Correct Answer: (A) typedef struct { ... } *ptr;
113. What is the output of the following code?
typedef int* ptr;
            ptr p1, p2;
            int x = 10;
            p1 = &x;
            printf("%d", *p1);
  • (A) 10
  • (B) 0
  • (C) Compilation error
  • (D) Undefined behavior
Correct Answer: (A) 10
114. When using typedef with arrays, what does it allow you to do?
  • (A) Create multiple array types
  • (B) Declare multiple variables of the same type in one line
  • (C) Allocate memory for arrays
  • (D) None of the above
Correct Answer: (B) Declare multiple variables of the same type in one line
115. How would you declare an array of 10 integers using typedef?
  • (A) typedef int arr[10];
  • (B) typedef int[10] arr;
  • (C) typedef arr int[10];
  • (D) int arr[10];
Correct Answer: (A) typedef int arr[10];
116. Which statement about typedef is FALSE?
  • (A) It can simplify complex declarations.
  • (B) It can create type aliases.
  • (C) It can be used to define constants.
  • (D) It can improve code readability.
Correct Answer: (C) It can be used to define constants.
117. Can you use typedef to create an alias for a function pointer?
  • (A) Yes
  • (B) No
  • (C) Only in C++
  • (D) Only for specific data types
Correct Answer: (A) Yes
118. What will happen if you do not include a semicolon at the end of a typedef declaration?
  • (A) It will compile successfully
  • (B) It will cause a syntax error
  • (C) It will be ignored
  • (D) It will create a default type
Correct Answer: (B) It will cause a syntax error
119. Which of the following is a valid definition of a typedef for a function that returns an integer and takes two integers as arguments?
  • (A) typedef int func(int, int);
  • (B) typedef int (*func)(int, int);
  • (C) typedef int func(int);
  • (D) typedef int func[];
Correct Answer: (B) typedef int (*func)(int, int);
120. How do you declare a variable st of type stu, where stu is defined using typedef for a structure?
  • (A) stu st;
  • (B) typedef stu st;
  • (C) struct st;
  • (D) struct stu;
Correct Answer: (A) stu st;