What is the purpose of typedef in C when used with structures ?

2024

What is the purpose of typedef in C when used with structures ?

  1. A.

    To define a new data type based on an existing one

  2. B.

    To declare a structure

  3. C.

    To specify the size of a structure

  4. D.

    To initialize a structure

Attempted by 133 students.

Show answer & explanation

Correct answer: A

typedef creates an alias for a structure type, allowing you to define variables without the struct keyword. For example, typedef struct {int x;} Point; lets you write Point p instead of struct Point p.

Explore the full course: Tpsc Assistant Technical Officer