两种结构体定义形式的区别

两种结构体定义方式的区别?

typedef struct {
} A;

struct B {
};


有什么区别?
------解决思路----------------------
A a;//正确
struct A a;// 正确
B b;// 错误
struct B b;// 正确
------解决思路----------------------
因此,区别就是A比struct B定义变量时,少输入一个struct!当工作量较大且使用频繁时起到作用!
------解决思路----------------------
第一种定义了一种结构体类型的别名A
第二种定义了一种结构体类型B

typedef
typedef type-declaration synonym;

The typedef keyword defines a synonym for the specified type-declaration. The identifier in the type-declaration becomes another name for the type, instead of naming an instance of the type. You cannot use the typedef specifier inside a function definition.

A typedef declaration introduces a name that, within its scope, becomes a synonym for the type given by the decl-specifiers portion of the declaration. In contrast to the class, struct, union, and enum declarations, typedef declarations do not introduce new types — they introduce new names for existing types.

Example

// Example of the typedef keyword
typedef unsigned long ulong;

ulong ul;     // Equivalent to "unsigned long ul;"

typedef struct mystructtag
{
   int   i;
   float f;
   char  c;
} mystruct;

mystruct ms;   // Equivalent to "struct mystructtag ms;"

typedef int (*funcptr)();  // funcptr is synonym for "pointer
                           //    to function returning int"

funcptr table[10];   // Equivalent to "int (*table[10])();"