關於一些C語言型別的問題

2021-09-28 15:46:22 字數 1543 閱讀 4833

按標準來說 ,最難辨別的幾個大小型別應該如下大小:

long >= int >= short

按自身理解(僅僅個人意見),long和short真實應該是long int和short int ,從而區分為32位還是16位。

但int應該是需要根據不同的編譯器來區分的,如在16位編譯時,就是16位長度。

按在有些公司的建議,有些程式不會建議使用int(因為對於不同mcu可能會導致不同的長度,從而使移植和復用變得麻煩),而是使用long和short,這樣可以更好的使模組進行移植和使用。

從網上總結的部分資料型別大小,只寫了位的大小,請注意有符號和無符號的取值範圍。

type

size

char

8bit

short

16bit

long

32bit

float

32bit

double

64bit

/*type definition of standard type bool*/

typedef

unsigned

char bool;

/*type definition of standard type u8*/

typedef

unsigned

char u8;

/*type definition of standard type u16*/

typedef

unsigned

short u16;

/*type definition of standard type u32*/

typedef

unsigned

long u32;

/*type definition of standard type u64*/

typedef

unsigned

long

long u64;

/*type definition of standard type s8*/

typedef

signed

char s8;

/*type definition of standard type s16*/

typedef

signed

short s16;

/*type definition of standard type s32*/

typedef

signed

long s32;

/*type definition of standard type s64*/

typedef

signed

long

long s64;

/*type definition of standard type f32*/

typedef

float f32;

/*type definition of standard type f64*/

typedef

double f64;

一些關於C語言的總結

看到一哥們寫的筆記,感覺不錯就拿過來了。本想加到網摘裡邊,可搗騰了半天就沒有發現加網摘的鏈結,最後還是寫到自己的部落格中吧!總結1 char ch 12345 char ch 12345 char ch puts printf s char ch 必須有單引號 scanf n a gets a 空格...

關於C語言的一些總結

最近看了一些書籍,總結一下程式設計師容易忽略的程式設計細節吧,對面試還是考試有幫助的,不斷更新中。1.sizeof 想必大家都知道這個關鍵字吧,不是函式哦,凡是在c c 編輯器了有和其它關鍵字有相同顏色的單詞都是關鍵字,這是乙個計算型別或者變數在記憶體中的佔位大小,當是型別時如sizeof int ...

關於型別轉換的一些問題

今天在寫 時使用乙個long long型別的變數儲存乙個數的累加,最後在輸入的時候發生了溢位。可能發生溢位的可能有幾個地方 1.其實變數並沒有溢位,只是在輸出時沒有使用正確的方式,例如long long型別 在使用printf時 識別符號應該使用 lld,unsigned longlong 應該使用...