1. 程式人生 > >數據類型所占用內存的大小

數據類型所占用內存的大小

變量 占用內存 定義 查看 pen 決定 size 驗證 pri

數據類型所占的大小是由編譯器和你電腦的架構共同決定的。

舉個例子: 定義一個int x=0;

那麽怎麽去查看到底這個int型的x變量占用的內存大小呢。

c++中提供了sizeof這個函數。

我們可以打印sizeof(x)去驗證,我的電腦上是占用4個bytes。

You may be surprised to find that the size of a given data type is dependent on the compiler and/or the computer architectureint!

數據類型所占用內存的大小