肯定很多新手和一样 被typedef难住了
比如说
typedef char *pchar;
我之前一直以为是把*pchar 等同于char(原文替换)
但是用新类型定义的时候又 解释不通 如下
pchar x;
等同于 char *x;
果断百度typedef 解释看了2遍也没看懂
突然想起有人说过不动了就去msdn检索
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])();"
注意最后一句的 注释
突然灵光一闪 这不就是把新定义的类型 定义的变量代回typedef吗?
试了几个例子 都能正确理解
好吧 我承认 我瞬间湿了
希望这个小发现能给新人带来方便
如果其中有哪里有什么不对的 也请大家及时指出 省的我以后犯错误