C语言之typeof关键字

直接从别人的部分例子拿过来,不知道算不算引用,还是加一下吧

原文: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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值