← Back to blog

[C/C++] Differences between `typedef struct` and `struct`

Computer Science > Programming

2026-10-261 min read

#computer-science #programming #C/C++

Before comparing the two forms, it is worth noting that C and C++ treat them differently.


C

In C, a structure is declared as follows.

struct Obj {
  int x;
  int y;
};

To declare a variable of this type, the struct keyword is required, as shown below.

struct Obj obj;

On the other hand, if you define an alias using typedef, you can declare a variable without the struct keyword.

typedef struct {
  int x;
  int y;
} Obj;

Obj obj;

C++

In C++, the two forms are equivalent for ordinary variable declarations.

::::comparison{columns="2"}

:::compare-card{title="typedef struct" badge="C++" description="Anonymous type with a typedef alias"}

typedef struct {
    int x;
    int y;
} Obj;

Obj obj;

:::

:::compare-card{title="normal struct" badge="C++" description="Named structure type"}

struct Obj {
    int x;
    int y;
};

Obj obj;

:::

::::