typeof() test demo

来源:互联网 发布:什么软件可以泡妞 编辑:程序博客网 时间:2024/06/03 20:44

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.exea 3, b 0x22cc64, c[0] 3 0x22cc64 var 4 d 4*/
0 0
原创粉丝点击