简体   繁体   中英

Pointers and typedef in C

In C,

int* a, b;

Will make a an integer pointer and b an integer.

What about this? Is b an integer or an integer pointer?

typedef int* foo;
foo a, b;

In C, typedef is not a preprocessor directive: unlike #define , it is not a textual substitution. 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* . Moreover, you can write this:

foo a, *b;

to make a an int* and b an int** .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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