在 C 中,寫進 sizeof() 中的任何東西都不會被執行
sizeof 函式(有時稱為運算子)用於計算給定引數的大小。如果將其他一些函式作為引數給出,那麼它將不會在 sizeof 中執行。
在以下示例中,我們將在迴圈中放置一個 printf() 語句。然後我們將看到輸出。
示例
#include<stdio.h> double my_function() { printf("This is a test function"); return 123456789; } main() { int x; x = sizeof(printf("Hello World")); printf("The size: %d
", x); x = sizeof(my_function()); printf("The size: %d", x); }
輸出
The size: 4 The size: 8
printf() 不會被執行,它存在於 sizeof() 中。只有返回型別被考慮,並且它的尺寸被採用。
廣告