直接从别人的部分例子拿过来,不知道算不算引用,还是加一下吧
原文:http://hi.baidu.com/leowang715/blog/item/b0b96d6f972e7dd080cb4a06.html
使用typeof的声明示例
下面是两个等效声明,用于声明int类型的变量a。
typeof(int) a; /* Specifies variable a which is of the type int */
typeof('b') a; /* The same. typeof argument is an expression consisting of
character constant which has the type int */
以下示例用于声明指针和数组。为了进行对比,还给出了不带
typeof
的等效声明。
typeof(int *) p1, p2; /* Declares two int pointers p1, p2 */ int *p1, *p2; typeof(int) * p3, p4;/* Declares int pointer p3 and int p4 */ int * p3, p4; typeof(int [10]) a1, a2;/* Declares two arrays of integers */ int a1[10], a2[10];如果将 typeof 用于表达式,则该表达式不会执行。只会得到该表达式的类型。以下示例声明了int类型的 var 变量,因为表达式 foo() 是 int 类型的。由于表达式不会被执行,所以不会调用 foo 函数。
extern int foo();
typeof(foo()) var;