03-sizeof的用法
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                03-sizeof的用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                ?
1、作用
sizeof運算符是C語言特有的運算符。
用來計算一個變量或者一個常量、一種數據類型在內存中所占的字節數。
2、基本形式
(1) sizeof (變量或常量)
(2) sizeof 變量或常量
(3) sizeof(數據類型)
(4)?不能是sizeof 數據類型, 即計算數據類型的字節數必須用小括號括起來
實例:
1> 計算常量和變量的字節數的時候,小括號可以有,也可以沒有
1 #include <stdio.h> 2 int main(int argc, const char * argv[]) 3 { 4 //計算常量的字節數 sizeof(常量) 或者 sizeof 常量 5 int size1 = sizeof(10); 6 int size2 = sizeof 10; 7 //計算變量的字節數 sizeof(變量) 或者 sizeof 變量 8 double a = 10.9; 9 int size3 = sizeof(a); 10 int size4 = sizeof a; 11 printf("size1 = %d\n", size1); 12 printf("size2 = %d\n", size2); 13 printf("size3 = %d\n", size3); 14 printf("size4 = %d\n", size4); 15 return 0; 16 }輸出結果為:
2> 計算數據類型的字節數
1 #include <stdio.h> 2 int main(int argc, const char * argv[]) 3 { 4 //計算數據類型的字節數 sizeof(數據類型) 5 int size5 = sizeof(char); 6 printf("size5 = %d\n", size5); 7 return 0; 8 }輸出結果:
當使用 sizeof char; 的時候:
轉載于:https://www.cnblogs.com/xdl745464047/p/4003155.html
總結
以上是生活随笔為你收集整理的03-sizeof的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: *在通配符及正则表达式中的差别
- 下一篇: 使用iometer测试
