---
title: "Use of typedef with structures"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:typedef-in-structures"
source: https://www.bctengineer.com/q/semester_1/computer_programming/typedef-in-structures
site: BCT Engineering
---

# Use of typedef with structures

Computer Programming · Chapter 8: Structures

- Asked in: 2070 Chaitra, 2 marks
- Video: [C_115 Structures in C using typedef | C Language Tutorials](https://www.youtube.com/watch?v=ojhbmh5SJsw) — Jenny's Lectures CS IT
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/typedef-in-structures
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

Explain the use of typedef keyword in structures.

## Short answer

typedef gives a new name to a struct type, so variables can be declared without 'struct' keyword. For example, 'typedef struct { char name[20]; int roll; } Student;' allows 'Student s;' instead of 'struct student s;'. The tag becomes optional.

## Answer

`typedef` gives a new name to an existing data type. With a structure, it lets us declare variables without writing the keyword `struct` each time, which shortens the code.

```c
typedef struct student {
    char name[20];
    int roll;
} Student;

Student s1, s2;     /* instead of: struct student s1, s2; */
```
Here `Student` is the new type name (not a variable). The tag `student` is optional; it can be left out, as in the program below.

```c
#include <stdio.h>

typedef struct {
    char name[20];
    int roll;
} Student;               /* Student is now a type name */

int main(void)
{
    Student s = {"Ram", 7};          /* no 'struct' keyword needed */
    printf("%s %d\n", s.name, s.roll);
    return 0;
}
```

Output: `Ram 7`

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does typedef do with a structure?
   A. Creates a variable
   B. Deletes the structure
   C. Makes members private
   D. Gives it a new type name so struct need not be written each time
   Answer: D. It shortens declarations. (Key point: Purpose)

2. In typedef struct {...} Student; what is Student?
   A. A type name, not a variable
   B. A variable
   C. A function
   D. A member
   Answer: A. Variables are declared as Student s1; (Key point: Name meaning)

3. Which declaration is valid after the typedef?
   A. struct Student s1;
   B. Student s1, s2;
   C. Student = s1;
   D. typedef s1;
   Answer: B. The typedef name is used directly, without struct. (Key point: Declaration)
