吾爱程序员:这里有好玩的游戏和软件
当前位置:首页C语言教程 → 用 sizeof() 写的任何东西都不会在 C 中执行

用 sizeof() 写的任何东西都不会在 C 中执行

来源:网络 | 更新时间:2022-01-10 21:02:28
在 C/C++ 中,sizeof() 运算符用于查找日期类型或变量的大小。用 sizeof() 编写的表达式永远不会执行。 例子:
// C program to demonstrate that the
// expressions written in sizeof() are
// never executed
#include <stdio.h>

int main(){

// The printf in sizeof is not executed
// Only the return type of printf is 
// considered and its size is evaluated
// by sizeof,
int a = sizeof(printf("hey"));

printf("%d", a);

return 0;
}
输出:
4
即使我们在 sizeof() 中赋值,更改也不会反映。
// One more C program to demonstrate that 
// the expressions written in sizeof() are
// never executed
#include <stdio.h>

int main() {
int a = 5;
int b = sizeof(a = 6);
printf("a = %d, b = %dn", a, b);
return 0;
}
输出:
a = 5, b = 4
   

最新文章

热点资讯

手游排行榜

CopyRight 2020-2030吾爱程序员

鄂ICP备2021004581号-8

本站资源收集于网络,如有侵权请联系我们:35492删除0109@qq.com