Unsigned keyword in C++

后端 未结 5 1585
醉酒成梦
醉酒成梦 2020-12-02 08:38

Does the unsigned keyword default to a specific data type in C++? I am trying to write a function for a class for the prototype:

unsigned Rotate(unsigned ob         


        
5条回答
  •  感情败类
    2020-12-02 09:24

    Does the unsigned keyword default to a data type in C++

    Yes,signed and unsigned may also be used as standalone type specifiers

    The integer data types char, short, long and int can be either signed or unsigned depending on the range of numbers needed to be represented. Signed types can represent both positive and negative values, whereas unsigned types can only represent positive values (and zero).

    An unsigned integer containing n bits can have a value between 0 and 2n - 1 (which is 2n different values).

    However,signed and unsigned may also be used as standalone type specifiers, meaning the same as signed int and unsigned int respectively. The following two declarations are equivalent:

    unsigned NextYear;
    unsigned int NextYear;
    

提交回复
热议问题