我剛剛在維基百科上找到該代碼。
鏈接:http://en.wikipedia.org/wiki/Sizeof#Use這是一個正確的語法(在維基百科上找到c代碼)?
代碼:
/* the following code illustrates the use of sizeof
* with variables and expressions (no parentheses needed),
* and with type names (parentheses needed)
*/
char c;
printf("%zu,%zu", sizeof c, sizeof(int));
它指出:「在Z字頭應該用來打印出來,因爲實際的大小可以在每個架構是不同的。」
我想它在我的編譯器,但它提供了以下結果:
「祖,祖」
+1 for -Wall ... – jcolebrand 2010-05-28 16:22:08
您可以使用'%lu'並明確地將'sizeof'值轉換爲'unsigned long' - 只要您知道對象的大小小於4GB,那麼您知道它肯定會被正確報告。 – caf 2010-05-29 13:44:49