Difference between unsigned char and char)

Source: Internet
Author: User
Char is unsigned
Unsigned char is unsigned and contains all positive numbers.

If both are used as characters, there is no difference, but there is a difference when using integers:
Char Integer Range:-128 to 127,
The Integer Range of unsigned char is 0 to 255.

In most cases, data of the char, signed Char, and unsigned char types share the same characteristics. However, when you assign a single byte number to a large integer number field, you will see their differences in symbol extension. Another difference is that when a number between 128 and 255 is assigned to the signed Char variable, the compiler must first convert the value, and a warning will also appear. It is easier to use unsigned char to assign values in hexadecimal notation. Depending on the compiler implementation, char is either equivalent to signed Char or equivalent to unsigned char.

Unsigned char * is the same as char.

Function: counts the number of Chinese characters in a string (the internal code of gb2312 is greater than 0xa0)

Char sztext [] = "12345 hello ";

L = strlen (sztext );
Int sum = 0;
For (INT I = 0; I <L; I ++)
If (sztext [I]> 0xa0)
Sum ++;
Sum/= 2;

In this way, you can calculate all Chinese characters,
Because char is signed, the maximum number is 127. If it is exceeded, it becomes the plural. For example, if 7f is 127, 80 is-1.
At this time, you must write
Unsigned char sztext [] = "12345 hello ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.