On the data type integral type in C #

Source: Internet
Author: User

1. Integral type:

Integral data is an integer.

Classification of integral types of data

The general classification of Integer data is as follows:

  • Basic type: The type specifier is int, which occupies 2 bytes in memory.
  • Short integer: The type specifier is a small int or shorter. Both the byte and the value range are the same as the basic type.
  • Long integer: The type descriptor is a long int or a long, which accounts for 4 bytes in memory.
  • Unsigned: The type descriptor is unsigned.
  • The unsigned type can also be matched with the above three types to form:
    • Unsigned basic: The type descriptor is unsigned int or unsigned.
    • Unsigned short integer: The type descriptor is unsigned.
    • unsigned long integer: The type descriptor is unsigned long.
    • Representation of integer data the integers mentioned above are in decimal. In the C language, there are also eight binary and hexadecimal. Here's a look at:

      1) Decimal number
      The decimal number has no prefix. Its digital is 0~9.

      The following are the valid decimal numbers: 237,-568, 65535, 1627;

      The following are illegal decimal numbers: 023 (cannot have leading 0), 23D (contains non-decimal digits).

      In the program is based on the prefix to distinguish the various binary numbers. Therefore, do not mistake the prefix in writing to cause incorrect results.

      2) Octal number
      The octal number must begin with 0, which is prefixed with 0 as the octal number. The digital value is 0~7. The octal number is usually an unsigned number.

      The following are valid octal numbers: 015 (decimal 13), 0101 (decimal 65), 0177777 (decimal 65535);

      The following are illegal octal numbers: 256 (no prefix 0), 03a2 (contains non-octal digits), 0127 (minus sign appears).

      3) Hexadecimal number
      The hexadecimal number is prefixed with 0X or 0x. Its digital value is 0~9,a~f or a~f.

      The following are valid hexadecimal numbers: 0X2A (decimal 42), 0XA0 (decimal 160), 0XFFFF (decimal 65535);

      The following are the illegal hexadecimal numbers: 5A (without prefix 0X), 0x3h (contains non-hexadecimal digits).

      4) Suffix of integer
      You can use the suffix "l" or "L" to denote the number of long integers. For example:
        • Decimal Long Integer number: 158L (decimal 158), 358000L (decimal 358000);
        • octal long integers: 012L (decimal 10), 077L (decimal 63), 0200000L (decimal 65536);
        • hexadecimal long integers: 0x15l (decimal 21), 0xa5l (decimal 165), 0x10000l (decimal 65536).

      The number of long integers is 158L and the basic integer number 158 is no different from the numeric value. But for 158L, because it is a long integer, the C compilation system allocates 4 bytes of storage space for it. And for 158, because it is a basic integer, it allocates only 2 bytes of storage space. Therefore, you should pay attention to the operation and output format to avoid errors.

      Unsigned numbers are also available as suffixes, and the unsigned number of integers is suffixed with "U" or "U". For example: 358u, 0x38au, 235Lu are unsigned numbers.

      Prefixes, suffixes can be used at the same time to represent various types of numbers. If 0xa5lu represents a hexadecimal unsigned long integer number A5, its decimal is 165.

      Definitions of several integer variables:
    • int a,b,c;  A,b,c is an integer variable long x, y;  X, Y is a long integer variable unsigned p,q;  P,q as unsigned integer variable

      The definition and use of "Example 3-2" Integer variable.
      #include <stdio.h>int main () {    int a,b,c,d;    unsigned u;    a=12;b=-24;u=10;    C=a+u;d=b+u;    printf ("a+u=%d,b+u=%d\n", c,d);    return 0;}

On the data type integral type in C #

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.