📜  用sizeof()编写的任何内容都不会在C中执行

📅  最后修改于: 2021-05-30 15:46:52             🧑  作者: Mango

在C / C++中,sizeof()运算符用于查找日期类型或变量的大小。用sizeof()编写的表达式永远不会执行。

例子:

// C program to demonstrate that the
// expressions written in sizeof() are
// never executed
#include 
  
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;
}
Output:
4

即使我们在sizeof()内分配一个值,更改也不会反映出来。

// One more C program to demonstrate that 
// the expressions written in sizeof() are
// never executed
#include 
  
int main() {
    int a = 5;
    int b = sizeof(a = 6);
    printf("a = %d,  b = %d\n", a, b);
    return 0;
}
Output:
a = 5, b = 4
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。