Signed and unsigned in No. 3 C ++

Source: Internet
Author: User

C ++ has four built-in arithmetic types: integer, floating point, single character, and Boolean value. An integer or floating point number. A single character can be of two types: signed and unsigned. The Boolean value does not exist. It is easy to understand the signed and unsigned types of integers and floating-point numbers. For example, the int range in general books is-32700--32700: unsigned int range: 0--65500. (Integer, floating point number is signed by default. That is, int, float is actually signed int and signed float)

 


The question is now

Start with c ++ primer.

 


Different from other integer types, char has three different types: normal char, unsigned char, and signed char. Although char has three different types, there are only two representation methods. You can use unsigned char or signed char to represent the char type. The char representation is determined by the compiler. "

 


Char is a character type. The ASCII code must be 0 to 127 characters in total. The signed char range is-127-127 or-128-128. The unsigned char range is 0-255. Both signed char and unsigned char can be used. enough to complete their own tasks. Char is implementation-related. You can add the option-funsigned-char during gcc compilation so that char is unsigned char by default.

There are three types of char, but there are only two Representation Methods. here we need to understand that char and signed char are different types, although in many cases signed char is the default option of char.

In c ++, it is legal to assign a negative value to the unsigned type. The result is that the negative value evaluates the modulo value of this type. Assign-1 to unsigned char and the result is 255.

 

 

So what are the functions of unsigned char? C ++ does not have a built-in byte data structure.


 

typedef unsigned char byte  typedef unsigned char byte

Customize.
It is quite convenient to use when applying for memory and bit operations.

 


We usually do not have special requirements when using it. We only need to use char. I think the lower-layer operations will use unsigned char.


 

Related Article

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.