C Primer Plus (3)

Source: Internet
Author: User

3.1 sample Program 3.2 variables and constant data

Some data can be pre-set before the program is used and remains unchanged throughout the running process. This is called a constant. In addition, data may change or be assigned a value during running, which is called a variable.

You must specify the type of the variable in the declaration statement.
Key words related to the seven data types given by K & r c: int, long, short, unsigned, char, float, double;
The two data type-related keywords provided by c90: signed and void;
Key words related to the three data types provided by C99: _ Bool, _ Complex, _ Imaginary; (Boolean value, plural number, Imaginary number)

The initialization variable is to assign an initial value to the variable.

C. Consider the number without the decimal point and index as an integer.
The prefix 0x or 0X indicates that the hexadecimal value is used, and the prefix 0 indicates that the octal value is used.
The choice of using different numeric systems is provided for convenience, and it does not affect the storage of numbers (binary encoding for storage ).
% D indicates a decimal number, % o indicates an octal number, and % x indicates a hexadecimal number. If you want to create a prefix for 0, 0x, and 0X, use the specifiers % # o, % # x, and % # X. Note (o is not 0 );
Other integer types
Short int type: It may occupy less storage space than the int type. It is a signed type.
Long int type: It may occupy more storage space than int type. It is a signed type.
Long int type: It may occupy more storage space than long type. It is a signed type. (Introduced in C99)
Unsigned int type: it can only be a non-negative value or a larger value.
The unsigned long int and unsigned short int are introduced in C90.
The unsigned long int is introduced in C99.

The short type can save storage space, and some hardware registers in the computer are 16 bits.

To print the unsigned int number, you can use the % u symbol. Print the long value. The % ld format specifier can be used. You can use the h prefix for the short type.

When using ASCII codes, pay attention to the differences between numbers and numbers. The ASCII value of character 4 is 52, and '4' is written to indicate symbol 4 instead of value 4.
Some C implementations regard char as a signed type, and others as a non-Signed type. You can check this information through the limits. h header file.

The most basic form of a floating point constant is: A signed sequence of digits containing the decimal point, followed by the letter e or E, followed by a signed value representing the 10 index. For example,-1.56E + 12 and 2.87e-3.
The positive number can be omitted. There can be no decimal point or exponent part, but not both. Do not use spaces in floating point constants.
C99 adds a hexadecimal format for a floating point constant. The prefix uses 0X/0x, followed by a hexadecimal number, followed by a p/P, followed by an index of 2.
For example, 0xa. 1fp10. Ah, 10. 1f indicates 1/16 plus 15/256, and p10 indicates the 10th power of 2. The decimal value is 10364.0.

Because C defines the length of the char type as one byte, sizeof reports that the double type is 4 bytes long in a system with a char type of 16 bits and a double type of 64 bits.

Standard C specifies that buffer content is transmitted to the screen in the following situations
1. When the buffer is full, 2 will encounter line breaks, and 3 will need to be input.
Passing the buffer content to a screen or file is called a refresh buffer.

Assume that ch is a char variable. Assign the escape sequence, decimal value, octal character constant, and hexadecimal character constant to a carriage return. (Assuming the ASCII value is used)

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.