亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 18159 | 回復(fù): 18
打印 上一主題 下一主題

char 和 unsigned char有什么區(qū)別? [復(fù)制鏈接]

論壇徽章:
1
IT運維版塊每日發(fā)帖之星
日期:2016-06-18 06:20:00
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2007-02-02 10:26 |只看該作者 |倒序瀏覽
請問unsigned char是什么類型?主要用于哪些地方?
和char 有什么區(qū)別?


什么時候用char, 什么時候用unsigned char?
char 是指哪些字符,unsigned char 是指哪些類型?

論壇徽章:
0
2 [報告]
發(fā)表于 2007-02-02 10:30 |只看該作者
搜搜
     http://www.cppreference.com/data_types.html

http://www.arm.linux.org.uk/docs/faqs/signedchar.php


  1. > consider this simple program:
  2.         > int main(void)
  3.         > {
  4.         >     char i = -1;
  5.         >     printf("%d\n", i);
  6.         >     return 0;
  7.         > }
  8.         >
  9.         > The print out is 255 in stead of -1, unless I define i as
  10.         > signed char i;
  11.         > then I get the "-1" print out.

復(fù)制代碼


  1. The character type is used to store characters - typically ASCII characters but not always. For example:

  2. char menuSelection = 'q';
  3. char userInput = '3';


  4. Note how a character is enclosed within single quotes. We can also assign numeric values to variables of character type:

  5. char chNumber = 26;


  6. We can declare signed and unsigned characters, where signed characters can have positive and negative values, and unsigned characters can only contain positive values.

  7. signed char myChar = 100;
  8. signed char newChar = -43;
  9. unsigned char yourChar = 200;


  10. Note that if we use a plain char, neither signed nor unsigned:

  11. char dataValue = 27;


  12. it may differ between compilers as to whether it behaves as a signed or unsigned character type. On some compilers it may accept positive and negative values, on others it may only accept positive values. Refer to your compiler documentation to see which applies.

  13. A char is guaranteed to be at least 8 bits in size. C++ also provides the data type wchar_t, a wide character type typically used for large character sets.

  14. An array of characters can be used to contain a C-style string in C++. For example:

  15. char aString[] = "This is a C-style string";


  16. Note that C++ also provides a string class that has advantages over the use of character arrays
復(fù)制代碼

[ 本帖最后由 bsdc 于 2007-2-2 10:44 編輯 ]

論壇徽章:
0
3 [報告]
發(fā)表于 2007-02-02 10:51 |只看該作者
找到句話

  1. In the ANSI C Draft Standard, the keyword signed was added, introducing a signed char type for all platforms. The new keyword solved the problem of not being able to use signed char portably, but at this point the standard committee could not mandate plain char to be signed. It would break a lot of code and upset vendors as well as users.

  2. The comprimise was to make signed char a type distinct from the two existing character types, while requiring char to have the same representation and values as either signed char or unsigned char. In other words, a char must look exactly like a signed char or unsigned char to the hardware; which one is implementation-defined. C++ later adopted this compromise for compatibility with C, so both languages now have three distinct char types.

復(fù)制代碼

說明char, unsigned char, signed char是三種類型,哈哈,char不像int 一樣默認為signed的,主要是為了不使得前面很多程序不至于被顛覆

論壇徽章:
0
4 [報告]
發(fā)表于 2007-02-02 19:09 |只看該作者

hehe

謝謝,學(xué)習(xí)了

論壇徽章:
0
5 [報告]
發(fā)表于 2007-02-02 22:21 |只看該作者
char 不是signed char那是什么呢,編譯器相關(guān)?

論壇徽章:
0
6 [報告]
發(fā)表于 2007-02-02 22:22 |只看該作者
原帖由 blackuhlan 于 2007-2-2 22:21 發(fā)表
char 不是signed char那是什么呢,編譯器相關(guān)?

對,是實現(xiàn)相關(guān)的,就是上面的plain char

論壇徽章:
2
2015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:11
7 [報告]
發(fā)表于 2007-02-03 09:52 |只看該作者
char跟編譯器的設(shè)置有關(guān),可以是signed char(一般默認),也可以是unsigned char

論壇徽章:
0
8 [報告]
發(fā)表于 2007-02-03 10:38 |只看該作者
unsigned char  通常用于需要做2進制操作時很有用
char 當(dāng)然是字符傳操作了

論壇徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-03 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-04 06:20:00
9 [報告]
發(fā)表于 2007-02-03 22:07 |只看該作者
to LZ:什么時候用unsigned int,什么時候用signed int?

論壇徽章:
0
10 [報告]
發(fā)表于 2007-02-03 23:57 |只看該作者
一般情況下用來沒什么區(qū)別,可能只是在位運算里面有點用。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP