简体   繁体   English

C中的指针和typedef

[英]Pointers and typedef in C

In C, 在C中

int* a, b;

Will make a an integer pointer and b an integer. 将使a整数指针和b一个整数。

What about this? 那这个呢? Is b an integer or an integer pointer? b是整数还是整数指针?

typedef int* foo;
foo a, b;

In C, typedef is not a preprocessor directive: unlike #define , it is not a textual substitution. 在C中, typedef不是预处理程序指令:与#define不同,它不是文本替换。 It gives an alternative name to an existing type, so both a and b will be of the same type - namely, foo , which is an alias for int* . 它为现有类型提供了一个替代名称,因此ab将具有相同的类型,即foo ,它是int*的别名。 Moreover, you can write this: 此外,您可以编写以下代码:

foo a, *b;

to make a an int* and b an int** . 使a int*b一个int**

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM