您的位置:首页 > 其它

typeof() test demo

2015-08-06 08:31 302 查看
typeof(x) y;

把y定义成x的数据类型;

其参数 x有2款类型;

1 表达式

// func为int类型, 即var为int类型变量

extern int fun();

typeof(fun()) var;

2 参数

typeof(int)

typeof(int *)

typeof(int *[4])

typeof(typeof(int *)[4])

typeof(*x) y;

typeof(*x) y[4]; //y是*x的数据类型, 该数据类型组成的数组;

#include <stdio.h>
#include <unistd.h>

int fun()
{

}
int main(int argc, char *argv[])
{
//declare  int a;
typeof(int) a;
//declare int *b;
typeof(int *) b;

//declare int *c[3];
typeof(typeof(int*)[3]) c;

typeof(b) d;
//declare expression;
typeof(fun()) var;
a = 3;
b = &a;
c[0] = b;
var = 4;
d = &var;
printf("a %d, b %p, c[0] %d %p var %d d %d\n", a, b, *c[0], c[0], var, *d);
return 0;
}

/*
$ g++ typeofDemo.cpp  -o td
$ ./td.exe
a 3, b 0x22cc64, c[0] 3 0x22cc64 var 4 d 4
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: