---
title: "Difference between “struct” and “typedef struct” in C++?"  
description: "Difference between “struct” and “typedef struct” in C++?"  
author: "Utpal Vishwas"  
published: 2023-07-07  
updated: 2023-07-10  
canonical: https://www.mindstick.com/forum/158998/difference-between-struct-and-typedef-struct-in-c-plus-plus  
category: "visual c++"  
tags: ["c++", "programming language"]  
reading_time: 2 minutes  

---

# Difference between “struct” and “typedef struct” in C++?

[Difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between “[struct](https://www.mindstick.com/blog/83/struct-in-c-sharp-dot-net)” and “typedef struct” in [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus)?

## Replies

### Reply by Aryan Kumar

In C++, the `struct` keyword is used to define a structure, which is a data type that can contain multiple different types of data. The `typedef` keyword is used to create an alias for a data type.

The main difference between `struct` and `typedef struct` is that `struct` defines a new data type, while `typedef struct` simply creates an alias for an existing data type. This means that you can use a `struct` to declare variables, while you can only use a `typedef struct` to refer to a variable that has already been declared using a `struct`.

For example, the following code defines a `struct` called `Point`:

C++

```plaintext
struct Point {
  int x;
  int y;
};
```

The following code declares a variable of type `Point`:

C++

```plaintext
Point point;
```

The following code declares a `typedef` called `Point` that refers to the `struct` of the same name:

C++

```plaintext
typedef struct Point Point;
```

The following code declares a variable of type `Point`:

C++

```plaintext
Point point;
```

In both cases, the variable `point` will be of type `Point`. However, the first code defines a new data type called `Point`, while the second code simply creates an alias for the existing data type `struct Point`.

In general, you should use `struct` if you want to define a new data type. You should use `typedef struct` if you want to refer to an existing data type without having to write out the full name of the data type every time you want to use it.


---

Original Source: https://www.mindstick.com/forum/158998/difference-between-struct-and-typedef-struct-in-c-plus-plus

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
