Chapter 1 C's Basic Elements

xiaoxiao2021-03-06  14

Chapter 1 C's Basic Elements

This chapter describes the composition elements of the C program language, including the name, array, and characters for constructing a C program. ANSI C grammar is called "Language Symbol", which explains how to define language symbols and how the compiler is evaluated.

Includes the following topics:

* Language symbol

* Note

*Key words

* Identifier

*constant

* String text

* Punctuation and specific characters

This chapter also includes reference tables for tricycons, floating point constants, integer constants and escape sequences. "Operator" is a symbol (a single character and character combination) that the specified value is operated, each symbol is interpreted as a single unit, called a language symbol. See Chapter 4, "Expression and Assignment" for more information.

Language symbol

In a C source program, the basic element identified by the compiler is "Language Symbol", and a language symbol is a source program text that the compiler cannot be divided into constituent elements.

Syntax language symbol:

Key words

Identifier

constant

String text

Operator

Punctuation

Note: For the explanation of the ANSI language specified, see the introduction part of the Appendix A "C language syntax summary" after this volume.

The keywords, identifiers, constants, string text, and operators described in this chapter are examples of language symbols. Point characters and middle brackets ([]), curly brackets (}), parentheses (()) and comma (,) are also language symbols.

Gum character

Space, Table, Wrap, Enter, Change Page, Vertical Tab and NewLine characters, because they have the same function, namely the word as the print page The blank between the lines makes it easier to read. Language symbols are bound by blank characters and other language symbols, such as operators and punctures. When the code is analyzed, the C compiler ignores the blank character unless used as a component of the separator or character constant or string text. Use blank characters to make programs more readable. Note that the compiler also processes the comment as a blank character.

Comment

A "annotation" is a character sequence that is starting with a combination of forward slash / asterpan (compiler as a single blank character, other ignored). A comment can contain any combination of characters that represent character sets, including changing characters, but do not have an "end annotation" delimiter (* /). Note can be more than one line but cannot nested. Note You can appear anywhere in a blank character, because the compiler processes a comment as a blank character, you cannot contain a comment in the language symbol, the compiler ignores the characters in the comment.

Using comment documentation your code, this example is a note accepted by the compiler:

/ * Comments CAN Contain Keywords Such AS

FOR AND while without generating errors. * /

Note You can appear in the same line with a code statement:

Printf ("Hello / N"); / * Comments can go here * /

You can choose a descriptive comment block before function or program module:

/ * Matherr.c illustrates Writing an error Routine

* for Math Functions.

* /

Since the comment cannot contain a nested annotation, this example causes an error:

/ * Comment Out this routine for testing

/ * Open file * /

FH = _open ("myfile.c", _ o_rdonly);

.. * /

This error occurs because the compiler identifies the first * /, the word Open file is followed by the end, which handles the remaining text, generate an error in * / when the comment is found outside. When you use a comment to indicate that some code behavior is tested, the preprocessor command #IF and #ENDIF, and the conditional compile is another useful method. For more information, see "Preprocessor Command" in the "Preprocessor Reference" behind this volume.

Microsoft Special Office

The Microsoft compiler also supports a single line of comments starting with two positive oblique lines (//). If you compile / za (ANSI standard), these comments produce errors, and these comments cannot exceed the second line. // this is a valid comment comment begins with two forward slope (//), the following line wrap characters end, can't add a escape character before adding. In the following example, the restriction has a reverse oblique line (/) to establish a "escape sequence". This escape sequence causes the compiler to handle the next line as part of the previous row (see "escape sequence" behind this chapter).

// my Comment / i ;

Therefore, i ; statement is annotated.

Microsoft C default is to enable Microsoft Expansion. Use / zA to close these expansion.

Microsoft End

Queuing of language symbols

When the compiler explains the language symbol, it contains as many characters as possible in a single language symbol before moving to the next language symbol. Because of this behavior, the compiler is not possible to interpret language symbols without blank characters, for expressions:

i J

In this example, the compiler first produces the longest possible operator ( ) from three plus numbers, and then processes the remaining plus number as an addition operator ( ). Therefore, this expression is interpreted as (i ) (j), not (i) ( J). In this similar case, use blank and parentheses to avoid blurring and ensure proper expression calculation.

Microsoft Special Office

The C compiler handle the CTRL z character for a file end indicator, which ignores any text after Ctrl Z.

Microsoft End

Key words

The keyword is a word having a specific meaning in the C compiler. In the translation stage 7 and 8, an identifier cannot and the C keyword has the same spelling and case (see the description of the conversion phase in the "Pre-Processor Reference" behind this volume; for information on the identifier, see the next section "Identifier"). C language uses the following keywords:

Auto Double Int Struct

Break else Long Switch

Case enum register type

Char Extern Return Union

Const Float Short unsigned

Continue for sign void

Default Goto Sizeof Volatile

Do if static while

You can't redefine keywords, but you can use the C prequel command to specify the text used to replace the keyword before compiling.

Microsoft Special Office

The ANSI C standard allows two underscore guided identifiers as reserved words that are compiled. Therefore, Microsoft agrees to specify the specified keyword of Microsoft to bring two underscores. These words cannot be used as the identifier name. For the description of the ANSI naming identifier, including the use of double underscores, see the next section "Identifier".

The keywords and specified identifiers identified by the Microsoft C compiler are as follows:

_ASM DLLIMPORT2 __INT8 NAKED2_

_BASED1 __EXCEPT __INT16 __STDCALL

__cdecl __fastcall __int32 thread2

__DECLSPEC __FINALLY __INT64 __TRY

DLLEXPORT2 __INLINE __LEAVE

1 .__, keyword limit for 32-bit target compilation.

2. These are the identifiers specified when using __Declspec, which are not limited in other contexts. Default Microsoft Expansion is allowed, in order to ensure that your program is completely portable, you are compiled to specify / zA option (ANSI compatible compilation) to close Microsoft Expansion. When you do this, Microsoft Specific keywords are prohibited.

When Microsoft is allowed to expand, you can use the keywords listed above in the program. In order to match ANSI, most of these keywords add a double downline prefix. However, there are four exceptions, namely DLLEXPORT, DLLIMPORT, NAKED and THREAD, only with __Declspc, so there is no need to boot two underscores. In order to be backward compatible, the remaining keywords are also supported by the remaining keywords.

Microsoft End

Identifier

"Identifier" or "Symbol" is the name of the variables, types, functions, and labels provided in your program. Identifiers must be different from keywords in spelling and case. You cannot use keywords (C or Microsoft) as identifiers, which are retained for specific purposes. You can create an identifier by specifying it in the description of the variable, type, or function. In the following example, Result is an identifier of an integer variable, while Main and Printf are identifier names of functions:

Void main () {int result; if (result! = 0) Printf ("BAD FILE HANDLE / N");} Once explained, you can use the identifier to reference the associated value in later program statements. A specific type of identifier, called a statement label, which can be used in the GOTO statement (whose description is described in Chapter 3 "Description and Type". Statement Number in Chapter 5 "Goto and Number Statements "Described in").

grammar

Identifier:

Non-numeric

Identifier

Identifier number

Non number: one of the following:

_ a b c d e f g h i j k L m N o P q r s t u v w x y z

A B C D E F G H i J K L M N o P Q R S T U v W x y

Number: One of the following:

0 1 2 3 4 5 6 7 8 9

The first character of an identifier name must be a non-number (i.e., the first character must be a downline or a uppercase or lowercase letter). ANSI allows 6 valid characters in the name of an external identifier, and 31 characters are allowed in the name of an internal identifier (in a function). External Identifiers (Description of Global Scope Description or Storage Class EXTERN) Overall, the additional naming restrictions, because these identifiers can be processed by other software such as linkers.

Microsoft Special Office

Although the ANSI allows 6 valid characters in the external identifier name, 31 characters are allowed in the internal identifier (in a function), but the Microsoft C compiler allows 247 characters in an internal or external identifier name. If you don't care about the compatibility with ANSI, you can use the / h option (limiting the length of the external name) to modify this default is a smaller or large value.

Microsoft End

The C compiler treats uppercase and lowercase letters as different characters. This feature is called "case sensitive", allowing you to establish different identifiers with the same spelling but have one or more different cases. For example, each of the identifiers below is unique:

Add

Add

Add

Add

Microsoft Special Office

Do not choose to start with two underscores for identifiers or add a name of a capital letter with a lower line. The ANSI C standard allows the identifier name that is starting with these character combinations to be used as a compiler. The identifier of the file layer range is not to name a lowercase letter with a lowercase. The identifier starting with these characters is also retained. Microsoft agreed to use a macro name of a underscore and a capital base and a Microsoft-specific keyword name starting with two underscores. In order to avoid any name conflicts, always choose the name that does not start with one or two underscores, or with a name of a big write letter with a lower line.

Microsoft End

The following example is a valid identifier that meets the ANSI and Microsoft naming limit:

j

count

Temp1

TOP_OF_PAGE

Skip12

Lastnum

Microsoft Special Office

Although the identifuct in the source file is sensitive, the symbols in the target file are not. Microsoft C processes the identifier in a compilation unit as sensitive. The Microsoft linker is sensitive, you must specify all identifiers based on case you consistency.

"Source Clearance" is a legitimate character set that can appear in the source file. For Microsoft C, the source character set is a standard ASCII character set. The source character set including the ASCII character is used as a symbol sequence. See "Character Constants" later in this chapter for information on executing the character set.

Microsoft End

An identifier has a "range", which refers to the program range of the program being known and "connected", which determines if the same name identifier is the same identifier in another range. These topics are explained in "Survival, Scope, Visibility, and Connection" in Chapter 2 "Program Structure".

Multi-byte and wide characters

A multi-byte character is a character consisting of one or more byte sequences. Each byte sequence represents a single character in the extended character set. Multi-character characters are used in strings such as Chinese characters. Wide characters are a variety of language character code that is always 16-bit wide. The type of character constant is char, for wide characters, which is Wchar_t. Since the width character is always fixed, the use of wide characters can simplify the programming of the international character set.

Wide string text L "hello" becomes an array of 6 integers of type Wchar_T:

{L'H, L'E, L'L, L "L", L'O ', O} Single Code Specification is a wide character specification. Running routines for converting multi-byte and wide characters include MBstowcs, MbTowc, WCSTOMBS, and WCTOMB.

Three letters

The source character set of the C source program is included in the 7-bit ASCII character set, but not the subset of ISO 646-1983invariant Code Set. The trigraph sequence allows the C program to write only ISO (International Standards Organization) Invariant Code Set. The three-letter is the three-character sequence (starting with two question marks) with the corresponding punctuation character. You can use tricycons in the C source file, the character set of the source file cannot contain some of the convenient graphical representation of certain punctuation characters.

Table 1.1 gives 9 three-alphabetic sequences. The punctuation characters of the first row that appear in all source files are replaced by the characters corresponding in the second column.

Table 1.1 Three-letter sequence

Three-letter punctuation character ?? = # ?? ([?? // ??)] ?? '^ ?? <{??! | ??>} ??

A three-letter is always processed as a single source character, in the first conversion phase, performs three-letter conversion before identifying the escape character in the character string and character constants. Only the 9 three letters listed in Table 1.1 are identified, all other characters are not converted.

Character escape sequence /? Prevent a character sequence similar to three letters from erroneous interpret (information on the escape sequence, see "escape sequence" behind this chapter). For example, if you try to print strings with the following printf statement!:

Printf ("what ??! / n");

Print string What | because ??! It is a three-letter, it is replaced by | characters. Correct printing this string is as follows:

Printf (what? /?! / n ");

In this printf statement, add a backslash transfi strip to prevent it before the second question mark! As a three-letter misuse.

Constant amount

A "constant" is a number, character, or string that can be used as a value in the program. Use constants to indicate floating point numbers, integers, enumerators, or character values ​​that cannot be modified.

grammar

constant:

Floating point constant

Integer constant

Enumeration

Character constant

Constants are described by having a value and a type. Floating point, integer and character constants are discussed in the following three sections. The enumeration is described in the "Experie Description" of Chapter 3, "Description and Type".

Floating point constant

A "floating point constant" is a decimal number indicating a sign of the symbol. Representation of symbol real numbers includes an integer part, a fractional portion, and an index. The floating point value that cannot be changed using floating point constants.

grammar

Floating point constant:

Fractal constant index part OPT floating point suffix OPT

Digital Sequence Index Partial Floating Point Sufficient OPT

Fractal constant:

Digital sequence OPT. Digital Series

Digital sequence.

Index section:

E Sword OPT Digital Sequence

E Sword OPT Digital Sequence

Symbol: one of the following

-

Digital sequence:

digital

Digital sequence number

Floating Point Suck: One of the following

f L f L

You can omit the numbers before the decimal point (the integer part of this value), or the number after the decimal point (decimal part), but it cannot be omitted. You can save the decimal point only if you include an index. There is no blank character separation between the numbers and characters of constants.

Several floating-point constants and expressions are described as follows:

15.751.575E1 / *=15.75

1575E-2 /*=15.75

-2.5e-3 /*= 0.0025/

25E-4 / *=0.0025/

Floating-point constants unless there is a negative (-) in front, otherwise it is a positive number. In this case, the negative number is treated as a single-grade calculation. Floating-point constants have type Float, Double, Long or long Double.

A floating point constant without F, F, L or L suffix has type Double. If there is an F or F suffix, the type of constant is float; if there is a letter L or a suffix, its type is long double. E.g:

100L / * has type long double * /

100F / * has type float * /

100D / * has type Double * /

Note that the Microsoft C compiler maps long double to the type Double Double. See Chapter 3, "Basic Type Storage" in Chapter 3, "Illustrated and Type".

You can omit the integer part of the floating point constant, as shown in the following examples. 75 can be represented in a variety of ways, including the following: .0075e2

0.075E1

.075E1

75E-2

Floating point constant limit

Microsoft Special Office

The restrictions of floating point constant values ​​are given in Table 1.2, and the header file float.h includes this information.

Table 1.2 Limitations of floating point constants

Constant meaning value of FLT_DIGQ number, Q1 decimal 6dbl_dig number floating point number can be rounded into a 15LDBL_DIG floating point representation 07FDBL_EPSILON 2.2204460492503131e-016LDBL_EPSILON 2.2204460492503131e-016FLT_GUARD 0FLT_MANT_DIG specified value of the digital base to ??????? FLT_RADIX ??????????????? DBL_MANT_DIG effective floating point numbers. The base is 2; 53LDBL_MANT_DIG Thus these values ​​may represent the maximum specified bit floating point 53FLT_MAX 3.402823466e 38FDBL_MAX 1.7976931348623158e 308LDBL_MAX 1.7976931348623158e 308FLT_MAX_10_EXP largest integer, the number of power 38DBL_MAX_10_EXP 10 is a floating-point representation 308LDBL_MAX_10_EXP 308FLT_MAX_EXP maximum integer, the number of power FLT_RADIX 128DBL_MAX_EXP representable floating-point number is a smallest positive number 1024LDBL_MAX_EXP 1024FLT_MIN 1.175494351-38FDBL_MIN 2.2250738585072014e-308LDBL_MIN 2.2250738585072014e-308FLT_MIN_10_EXP minimum negative integer, the number is a power of a -37DBL_MIN_10_EXP 10 Representing the floating point number -307LDBL_MIN_10_EXP -307FLT_MIN_EXP minimum negative integence, ??????? FLT_RADIX ????? - 125dBL_MIN_EXP ????? The number of this number -1021LDBL_MIN_EXP is a represented floating point number -1021FLT_NORMALIZE 0 FLT_RADIX Index represents the base 2_dbl_radix 2_ldbl_radix 2flt_rounds floating point plus rounding 1 (near) _dbl_rounds mode 1 (near) _LDBL_ROUNDS 1 (near)

Note: The information in Table 1.2 may have different implementations in the future.

Microsoft End

Integer constant a "integer constant" means a decimal (base 10), an octal (base 8) or hexadecimal (base 16). Using an integer constant indicates an integer value that cannot be changed.

grammar

Integer constant:

Decimal constant integer suffix OPT

Octa constant integer suffix OPT

Hexadecimal constant integer suffix OPT decimal constant:

Non-0 digital decimal constant digital octal constant:

0

Octa-made constant eight feed numbers

Hexadecimal constant:

0x hexadecimal number

0x hexadecimal number

Hexadecimal constant

Hexadecimal number non-0 Number: one of the following

1 2 3 4 5 6 7 8 9

Okimony: one of the following

0 1 2 3 4 5 6 7

Hexadecimal number: one of the following

0 1 2 3 4 5 6 7 8 9

A b C D e f

A b C D e f

Integer suffix:

No symbolic suffix long integer suffix OPT

Long integer suffix unsigned suffix OPT

No symbolic suffix: one of the following

u u u u

Long integer suffix: one of the following

l L64 bit integer suffix:

i64

It is a positive number unless the integer constant has a negative (-). The negative sign is interpreted as a single-grade calculation of the counter operator (information about this operation, see "Single Math Operator" in Chapter 4 "Expression and Assignment").

If an integer constant starts at an 0x or 0x letter, it is a hexadecimal; if it starts with numbers 0, it is an eight-input number; otherwise it assumes a decimal number.

The following two lines are equivalent:

0x1c / * decimal number 28 of the number of 16-year-old representation * /

034 / * Decimal number 28's octal representation * / an integer constant number cannot be separated by a blank character. The following example is a valid decimal, octal and hexadecimal constant:

/ * Decimal constant * /

10

132

32179

/ * Octocarns * /

012

0204

076663

/ * Hexadecimal constant * /

0xa or 0xA

0x84

0x7db3 or 0x7db3

Integer type

Each integer constant is given a given type based on its value and means. You can force any integer constant as a long type by adding letters L or L at the end of a constant. It is forced to be a unsigned type by adding U or U. Small-write letter L may be confused with numbers 1 and should avoid this. The format of several long integer constants is as follows:

/ * Long decimal constant * /

10L

79L

/ * Long octarinary constant * /

012L

0115L

/ * Long hexadecimal constant *

/ 0xAL or 0xAL

0x4fl or 0x4fl

/ * No symbol long decimal constant * /

776745UL

778866lu

You assign a type of constant depends on the value represented by this constant. A constant value must be within the range of values ​​whose type can be represented, the type of constant determines the conversion that is performed when the constant is used for an expression or applies a negative (-). Here lists the conversion rules of integer constants:

* There is no suffix of decimal constants with int, long int or unsigned long int. The first type in the three types of the value of this constant may be represented as a type assigned to the constant.

* There is no suffix of octal and hexadecimal constants assigned to the size of the constant can be int, unsigned int, long int, or unsigned long int.

* The type of constant with U or U suffix is ​​assigned according to their size, depending on their size, can be unsigned int or unsigned long int. l The type of constant assigned by the L or L suffix may be a long int or unsigned long int.

* The type with u or U and L or L suffixes is assigned to unsigned long int.

Integer limit

Microsoft Special Office

Table 1.3 lists the limitations of integer types,

These restrictions are defined in the standard header file LIMITS.H.

Microsoft C also allows you to indicate that the variable size variable can be an integer type of 8 bits, 16-bit or 32-bit, information about the variable size integer, see Chapter 3, "Description and Types" Size integer type.

Table 1.3 limitations of integer constants

Constant Meaning CHAR_bit is not a bit number of bits 8Schar_MIN Type SIGNED CHAR Maximum Variables of the Variable of the Variable of the Signed Char 127uChar_max Type Unsigned Char Maximum Variables of the Variables 225 (0xFF) CHAR_MIN Type Char The minimum value of the variable is -128; if the / j option is used for the maximum value of the variable of 0CHAR_MAX type char; if using the / j option, the maximum number of bytes in the 255MB_LEN_MAX multi-character constant 2Shrt_MIN Type SHORT variable minimum maximum variable maximum 2147483647UINT_MAX type unsigned int, int type variables minimum -2147483647-1INT_MAX variable maximum value of 65535 32767USHRT_MAX variable type variable -32768SHRT_MAX type short for unsigned short (0xffff) INT_MIN of type int 4294967295 (0xfffffff) LONG_MIN Type LONG Variable Minimum Variables - 2147483647-1long_max Type LONG Variable Maximum Value 2147483647ULONG_MAX Type Unsigned LONG Variables 4294967295 (0xffffFFFF)

If a value exceeds the maximum integer, the Microsoft compiler produces an error. Microsoft End

Character constant

A "character constant" is made up of a single character in the character set by single quotes (''). Character constants can be used to represent characters in the character set.

Syntax character constant:

'C Character Sequence'

L'C Character Sequence '

c Character sequence:

c character

C character sequence

c character c character

Source Character Concentration In addition to the single quotes ('), reverse slash (/) or any member other than the newline character.

Escape sequence

Side sequence:

Simple escape sequence

Octa-based transfusion sequence

Hexadecimal transfusion sequence

Simple escape sequence: one of the following:

/ a / b / f / n / r / t / v

/ '/ "// /?

Octa-entered transfusion sequence:

/ Octal number

/ Octal digital octal number

/ Octal digital octal digital eight reformed number

Hexadecimal transfusion sequence:

/ x hexadecimal number

Hexadecimal transfusion sequence hexadecimal number

Character type

A integer character constant does not begin with the letter L and has an int type. A value of an integer character constant containing a single character is the value of a character explained as an integer. For example, the value of character A is a decimal 97 and hexadecimal 61.

From the grammar, a "wide character constant" is a character constant with a prefixed letter L. A wide character constant has type WCHAR_T, an integer type definition in the stddef.h header file, for example:

Charschar = 'x'; / * A character constant * /

Wchar_t wchar = l'x '; / * A wide character constant of the same character * /

The wide character constant has 16-bit wide and points out the members of the extended execution character set. They allow you to use a letter that is too large from type char. For more information on wide characters, see "Multi-byte and Wide Characters" in front of this chapter.

Enforce character set

This book often refers to "Executive Character Set". The execution character set does not have to be identical to the source character set used by the write C program, the execution character set includes all characters in the source character set, the empty character, wrap, back, the retardation, horizontal tab, vertical tab, the carriage return and escape sequence . Source character sets and execution character sets may differ in other implementations.

Escape sequence

The character combination of a letter or a digital composed of a reaction slash (/) is referred to as a "escape sequence". In order to indicate a resort, single quotes, or some other character constants, you must use the escape sequence. A escape sequence is a single character, so it is a valid character constant. The escape sequence is generally used to point out the action, such as the carriage return and tab on the terminal and the printer, which are also used to provide non-print characters and characteristic characters, such as the two quotes. Table 1.4 lists the ANSI escape sequences and their representation.

Note that after the reverse slash (/?) Points to a text question mark, in this case, the character sequence may be misinterpreted as a three-letter, about more information, see "Three Letters" in front of this chapter .

Table 1.4 Side escape sequence

Side sequence representation / A ring bell (warning) / B retracted / F change page / N wrap / R carriage / T horizontal tab / V vertical tabulation / 'single quotes / "double quotes // reverse slash /? Text question mark / OOO ASCII character / xhhh hexadecimal represented ASCII characters

Microsoft Special Office

If the reverse slash before a character does not appear in Table 1.4, the compiler processes the undefined character to the character itself, for example, / x as an X process.

Microsoft End

The escape sequence allows you to transfer the non-graphic control character to a display device, for example, the ESC character (/ 033) is often used as the first character of a terminal or printer's control command. Some escape sequences are specific. For example, vertical tab and switch escape sequences (/ v, and / f) cannot be used for screen output, while they perform appropriate printer operations.

You can use a backslash (/) as a continuation, when a newline is equivalent to RETURN, immediately follow the backslash (/), the compiler ignores the backslash and the newline character, The next line is part of the front line. This is mainly used for more than one line of preprocessing definition, for example:

#define assert (EXP) /

((eXP)? (void) 0: _assert (# exp, _ _file_ _, _ _line_ _))

Okiminary and hexadecimal character specifications

Sequence / OOO indicates that you can specify any characters in the ASCII character set in a three-digit octal character code, which specifies the value of the outstanding character or wide character. Similarly, sequence / xhhh allows you to specify any ASCII characters in a hexadecimal code, for example, you can code (/ b) or / 010 (octal) or / x008 with normal C escape (/ b) or / 010 (sixteen) The credit code gives the ASCII backfix.

You can only use 0 to 7 numbers in an octave transfusion sequence. The octal transfusion sequence cannot be longer than 3 numbers and end with characters that are not an octal number. Although you don't need to use all three numbers, you must use at least one, for example, an octal representation of the ASCII backout is / 10, and the octal representation of the letter A is / 101, as given by the ASCII table.

Similarly, you must give at least a number for the hexadecimal transfusion sequence, but you can omit the second and third numbers. Therefore, you can point out the hexadecimal sequence sequence / x8, / x08 or / x008. The value of the octal or hexadecimal transformation sequence must be within such a representative range of the character constant is the representative value range of the type unsigned char; for wide character constants, the representative value range of type WCHAR_T. See "Multi-byte or Wide Character" in front of this chapter on the information about wide character.

Different from the eight-input escape constant, the value of hexadecimal numbers in a escape sequence is unlimited, and a hexadecimal transfusion sequence terminates with the first character that does not belong to a hexadecimal number. Because hexadecimal numbers include word letters A to F, be careful to ensure that the escape sequence terminates at the specified number. To avoid confusion, you can place an octal or hexadecimal character definition in a macro definition:

#define bell '/ x07'

For hexadecimal values, you can break down the string to clearly display the correct value:

"/ XABC" / * A character * /

"/ xab" "c" / * two characters * /

String text

A "string text" is a character sequence enclosed in a single quotation number ("") in the source character set. String text is used to represent a character sequence of a string ending with a space character, for a wide string text, before it must be prefixed.

Syntax string text:

"S Character Sequence OPT"

L "S Character Sequence OPT"

s Character Sequence:

s character

S Character Sequence S Character

s Character:

Source Character Concentration In addition to double quotation marks ("), reverse slash (/) or any member outside the newline

Escape sequence

The following example is a simple string text:

"" "" "" "" "" "" "" "" "" "" "" ""

All escape codes listed in Table 1.4 are valid string text. In order to represent a bracket in a string text, use the escape sequence / ". Single quotes (') no escape sequence can also be represented. Reverse slash (/) in a string is a must With the second reverse slash (//). When a reverse slash appears at the end of a row, it always interprets a continuation.

String text Type

String text has a type array of char (also char []) (wide string has a type array of Wchar_t (that is, Wchar_T [])). This means that a string is an array with type char elements. Element members in this array are equal to the character string, plus 1, ending space characters.

String text storage

A string text is stored in adjacent memory locations. One escape sequence (for example // or / ") in a string text is a single character count. A space character (represented by / 0 escape sequence) is automatically added as the end of each string text (this In the conversion phase 7). Note The compiler is not possible to store two identical strings in different addresses. /GF (Delete Repeat String) Compiler Option Force the compiler to copy the same string into the executable.

Microsoft Special Office

The string has a static memory period. For information on static memory, see Chapter 3 Description and Types "Storage Class".

Microsoft End

String text connection

In order to form a string text that occupies multi-line, you can connect two strings. To do this, type a reverse slash and press the Return key. The reverse slash causes the compiler to ignore the backward wrap. For example, string text:

Long strings can be Bro /

Ken Into Two or more Pieces. "

The text is the same as the following string text:

"Long strings can be broken into two or more pieces."

A string connection can be used to previously adopted a back slash with a wrap character to enter more than one line of string text.

In order to force the wrap in a string text, insert a part of the row (/ N) in the place in this string, as follows:

"Enter a Number Between 1 and 100 / Nor Press Return"

Because the string can start in any column in the source code, and the long string can continue to any column of the next row, you can locate the readability of the source code, no matter which case output is not influences. E.g:

Printf ("This Is The First Half of The String," This Is The Second Half ");

Each part of the string is included in the dual quotation, each part is connected as a single string to output, which is executed in the compilation of the translation phase.

"This is the first hAlf of the string, this is the second half"

A string pointer initializes two different string texts separated by blank, and is discussed as a single string (pointer in Chapter 3 "Description and Type" in "Pointer Description"). Suitably, as follows, the results are the same as the previous example:

Char * String = "this is the first hAlf of the string,"

"this is the second house";

Printf ("% s", string);

In the conversion phase 6, the multi-byte character sequences specified by any adjacent string or adjacent width string text sequence are connected to a single multibly character sequence. Therefore, do not design such a program, allowing the string text to be modified in the execution. The ANSI C standard indicates that the result of modifying a string is uncertain.

Maximum string length

Microsoft Special Office

ANSI compatibility requires a compiler to receive 509 characters in a string text after the connection, and the maximum length of a string text allowed in Microsoft C is close to 2048 bytes. If the string text consists of partially included in the dual quotation, the preprocessor connects these parts to a single string. For each connection, an additional byte is added to the total number of bytes.

For example, suppose a string consists of 40 lines, 50 characters per row (a total of 2000 characters), and another 7 characters, each line is enclosed in double quotes, so 2007 bytes plus end space characters One byte, a total of 2008 bytes. In connection, each line adds an additional character to the first line, which has a total of 2048 bytes. Note that if the renewal (/) is used instead of dual quotation marks, the preprocessor does not add an additional character for each line.

Microsoft End

Points and special characters

There are various purposes and special characters in the C character set, from the organizers text to the execution function of the compiler or compiled program. They do not specify the operation of the execution. Some punctuation is also an operator (see "Operators" in Chapter 4, "Expression and Assignment"). The compiler determines their use from the context.

grammar

Practice: one of the following

[] () {} *,: =; ... #

These characters have specific meanings in C, which are described in this book. # 号 (#) only appears in the preprocessing command.

转载请注明原文地址:https://www.9cbs.com/read-46769.html

New Post(0)