C- Typedef Questions and Answers

Practice Mode
Showing 10 of 23 questions
Q1
In the following code, the P2 is Integer Pointer or Integer? typedef int *ptr; ptr p1, p2;
  • A Integer
  • B Integer pointer
  • C Error in declaration
  • D None of above
Answer: Option B
Q2
In the following code what is 'P'? typedef char *charp; const charp P;
  • A P is a constant
  • B P is a character constant
  • C P is character type
  • D None of above
Answer: Option A
Q3
What is x in the following program? #include<stdio.h> int main() {     typedef char (*(*arrfptr[3])())[10];     arrfptr x;     return 0; }
  • A x is a pointer
  • B x is an array of three pointer
  • C x is an array of three function pointers
  • D Error in x declaration
Answer: Option C
Q4
What is the primary purpose of typedef in C?
  • A To create new data types
  • B To create alias names for existing types
  • C To define constants
  • D To allocate memory
Answer: Option B
Explanation: typedef creates alias names for existing types
Q5
Which of the following is the correct syntax for typedef?
  • A typedef new_name existing_type;
  • B existing_type typedef new_name;
  • C typedef existing_type new_name;
  • D new_name typedef existing_type;
Answer: Option C
Explanation: typedef is followed by existing type and then new name
Q6
What does typedef do with structures?
  • A Allocates memory for structure
  • B Creates shorter names for structures
  • C Initializes structure members
  • D Defines structure size
Answer: Option B
Explanation: typedef can create shorter names for structures
Q7
Which statement about typedef is FALSE?
  • A Creates type aliases
  • B Can be used with structures
  • C Can be used with pointers
  • D Creates new memory locations
Answer: Option D
Explanation: typedef doesn't create new types, just aliases
Q8
How to declare a typedef for an integer pointer?
  • A typedef int_ptr int*;
  • B typedef int* int_ptr;
  • C typedef *int int_ptr;
  • D typedef int int_ptr*;
Answer: Option B
Explanation: Use typedef with int* and new name
Q9
What is the advantage of using typedef with function pointers?
  • A Reduces code size
  • B Increases execution speed
  • C Makes code more readable
  • D Automatically initializes pointers
Answer: Option C
Explanation: Function pointers become more readable with typedef
Q10
Can typedef be used with arrays?
  • A No, arrays cannot be typedefed
  • B Yes, but only 1D arrays
  • C Yes, arrays can be typedefed
  • D Only with constant size
Answer: Option C
Explanation: Yes, typedef can create array type aliases
Questions and Answers for Competitive Exams Various Entrance Test