C Language Review 3/6 days

Source: Internet
Author: User

1. Variable: A variable represents a named storage unit with a specific attribute. It is used to store data, that is, the value of the variable. The value of a variable can be changed while the program is running. Variables must be defined before they are used. Variable names and variable values are two different concepts. The variable name is actually a storage address represented by a name. The compiled system assigns a corresponding storage address to each variable name when it compiles a connection to the program. By taking a value from a variable, you actually find the corresponding memory address from the variable name and read the data from that storage unit.

2. Symbolic constants: Use the # define directive to specify that a symbol name represents a constant. such as # define PI 3.14

Note: Symbolic constants are not variables, symbolic constants do not occupy memory, only a temporary variable, after precompilation this symbol does not exist, it is not possible to assign a new value to the symbol constant.

3. Escape characters \o, \oo, \ooo (o for an octal digit) output the character corresponding to the octal code

printf ("\101");//the output is a; 1018 is converted to decimal 65, the corresponding ASCII character is a

Escape character \xh[h ...] where h represents a hexadecimal number, and the output is the character corresponding to the hexadecimal code.

printf ("\x1b");//output is ESC control, 1B is converted to decimal 27, 27 corresponds to the ASCII character ESC

4. Constant variables

const int a = 3;

A is defined as an integer variable, specifying its value to be 3, and its value cannot be changed during the existence of a variable.

The similarities and differences between constant variables and constants are: constant variables have the basic properties of variables: There is a type, the storage unit, but it is not allowed to change its value. It can be said that the constant variable is a non-variable with a name, and a constant is a non-variable with no name. A name is easy to refer to in a program.

5.C99 standard new data types: Double long int, boolean bool, pointer type *

Note: The C standard does not specify the length of storage units used by various types of data, which is determined by each compilation system. The C standard only requires a long type that is not shorter than the int type, and the short type is not longer than the int type.

namely: sizeof (short) <=sizeof (int) <=sizeof (long) <=sizeof (long Long)

Variable values for integer variables are stored in complementary form in the storage unit, and the first bits in the storage cell represents the symbol.

About the complement: positive integer complement is the original code, negative integer complement to the absolute negation code, anti-code plus 1 is the complement

Integer variable can be added unsigned modifier, to specify that the integer variable is an unsigned integer, output when the specified output format unsigned decimal number format output%u, after a variable is defined as an unsigned integer, it should not be given a negative value, or you will get the wrong result. such as: unsigned short price = -1;printf ("%d\n", price);//output result is 65535

Reason: 1 converted to complement: 11111111 11111111, the first place on the left does not represent symbols, output in%d format, that is, 65535 that is 2 16 square-1

6. Character data is stored in a way that stores its ASCII code, so C99 also takes character data as one of the integer types.

C99 allows the use of the whcar_t type (wide character) in addition to the char type (single byte), whose type is defined in the header file stddef.h.

7. The character ' 1 ' and the integer 1 are different concepts, the character ' 1 ' simply represents a symbol with a shape of ' 1 ', which, when needed, is output as-is, is stored in memory in ASCII format, occupies 1 bytes, the ASCII code of the character ' 1 ' is 49, and is stored as 00110001, The integer 1 is stored in twos complement form, accounting for two or 4 bytes 0000 0000 0000 0001

8. Character types also belong to integers, and you can use the signed and unsigned modifiers. If the variable is defined without signed and unsigned,c the standard does not specify whether to press signed char processing or unsigned char processing, the compilation system itself. This is different from other integer variable handling methods, such as int by default equal to signed int.

If assigning a negative integer to a signed character type variable is legal, it does not represent a single character, but instead stores a negative integer as a byte integer variable.

Such as:

Signed char C =-6;
printf ("%d", c);//output IS-6

8. In the C language, real numbers are stored in exponential form in the storage unit.

The compilation system allocates 4 bytes for each float variable, and the value is stored in the storage unit as a normalized binary number exponent. When stored, the system divides the real data into fractional parts and two parts of the exponential part, respectively. The number of decimal points before the fractional number is 0. In 4 bytes, how many bits to represent the fractional part, how many bits to represent the exponential part, C standard does not specify, the C language compiled by the system itself.

C Language Review 3/6 days

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.