0X02 data and C, 0X02 data

Source: Internet
Author: User

0X02 data and C, 0X02 data
Overview

The data types in C language include basic type, construction type, pointer type, and null type.

The null type is void. The pointer type is not mentioned here, and the constructor type (array, struct, Consortium, enumeration, and nesting) is not mentioned here.

Basic types: short, int, long, char, float, and double ). Six Types

There are also unsigned integer (unsigned int, short for unsigne), long integer (long int, short for long, C99 added unsigned long int type

The signed keyword can be used with any signed type, which is more precise for the data type. Short, short int, signed short, and signed short int represent the same type.

The memory size of the six basic data types varies with different platforms. Use the following code to check the memory:

 

Printf ("int ----- % d \ n", sizeof (int ));
Printf ("long ---- % d \ n", sizeof (long ));
Printf ("short --- % d \ n", sizeof (short ));
Printf ("float --- % d \ n", sizeof (float ));
Printf ("double -- % d \ n", sizeof (double ));
Printf ("char ---- % d \ n", sizeof (char ));

When using printf (), remember that each value to be displayed must correspond to its own format specifier, and the type of the displayed value matches the specifier.

It is a good habit to initialize a variable when it is declared. Although not doing this, there is no big problem, but there is always a chance to have unexpected results.

Escape sequence:

\ A alarm; \ B backspace; \ f paper feed; \ n line feed; \ r carriage return; \ t horizontal tab; \ v vertical tab; \ backslash (\); \ 0a octal value (a is the octal number); \ xa hexadecimal value (a is the hexadecimal number)

 

Reasons for using multiple integer types

To adapt to different machines

The long type is 64-bit, the long type is 32-bit, the short type is 16-bit, And the int type is 16-bit or 32-bit (depending on the machine's natural word size ). In principle, the four types represent four values of different sizes.

Corresponding 16-bit unit: the minimum value range of the short and int types is-32767 to 32757.

Corresponds to 32-bit units. The minimum value range of the long type is-2147483647 to 2147483647; the minimum value range of unsigned short and unsigned int is 0 to 65535; and the unsigned long is 0 to 4294967295.

The long type corresponds to 64-bit requirements, range:-9 223 372 036 854 775 807 to 9 223 372 036 854 775 807

Unsigned long is 0 to 18 446 744 073 709 551 615

(Learn the principles of computer science about how the data is obtained .. After learning about binary encoding, you will know what is going on)

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.