您的位置:首页 > 其它

typeof关键字

2010-04-27 00:55 141 查看
typeof是gcc对于标准c的一个扩展,用来获取变量的类型。请看下面的例子:

#include <stdio.h>

int main()
{
char* ptr = NULL;

typeof(*ptr) chr = 'w';

printf("%c/n", chr);

return 0;
}

编译并执行:

[root@localhost typeof_test]# gcc -o test_typeof test_typeof.c
[root@localhost typeof_test]# ls
test_typeof test_typeof.c
[root@localhost typeof_test]# ./test_typeof
w

上面的例子中,ptr是char*类型,*ptr就是char类型,用typeof来获取类型后,定义变量

chr,等同于char chr = 'w';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: