Confusion about 2 names in C: escape sequence, floating point numbers
I'm referring to C. Both the textbook and wikipedia don't give a clarified a开发者_开发技巧nswer, can anyone tell me why these two weird names?
Escape sequences are sequences of characters that begin with the escape character, the backslash (\
). The backslash causes the following character(s) to "escape" their normal meaning.
b -> \b # Backspace
n -> \n # Newline
0 -> \0 # NUL
x40 -> \x40 # Character code 0x40
Fixed-point numbers always have the same number of positions after the radix point, even if they are displayed with more or less. Floating-point numbers have a variable number of positions after the radix point, defined by a bitfield within the number itself.
Fixed point:
1.0000
12.3456
Floating point:
1.02
345.6
Floating-Point Numbers //this is wikipedia, but the article is good and simple, don't say it doesn't help
Example:
1.23f
4.20
6e-2 //same as 0.06 i.e. 6*10^-2
terminology: floating-point (as opposed to fixed-point) because the internal representation doesn't specify certain number of bits for whole part and fractional part. Thus, the point is floating.
Escape Sequences
Example:
\n //newline
\t //tab
\r //caret return
The names seem not too weird if you think at them metaphorically. An "escape sequence" is a sequence of character that "escapes" common rule of something. "Floating point numbers" are numbers where the point (decimal point) can "float" (referring to its position), i.e. it can be "anywhere".
Escape sequence is a portion of a string containing a special character. For instance, if you need double quotes inside a string literal (remember, string literals are enclosed within double quotes), then you use the following escape sequence:
\"
Floating point numbers are arbitrary precision numbers using floating point representation (i.e., 2.56, 3.1415, you get the idea). Read about number representation somewhere, and you will learn a lot about them.
精彩评论