1 int x; x=-3+4%-5*3;则x的值为 2 先算4%-5==4%5的值为4 3 再算4*3==12 4 再减-3 5 最后答案就是9
Precedence | Operator | Description | Example | Associativity |
---|---|---|---|---|
1 | () [] -> . :: ++ -- |
Grouping operator Array access Member access from a pointer Member access from an object Scoping operator Post-increment Post-decrement |
(a + b) / 4; array[4] = 2; ptr->age = 34; obj.age = 34; Class::age = 2; for( i = 0; i < 10; i++ ) ... for( i = 10; i > 0; i-- ) ... |
left to right |
2 | ! ~ ++ -- - + * & (type) sizeof |
Logical negation Bitwise complement Pre-increment Pre-decrement Unary minus Unary plus Dereference Address of Cast to a given type Return size in bytes |
if( !done ) ... flags = ~flags; for( i = 0; i < 10; ++i ) ... for( i = 10; i > 0; --i ) ... int i = -1; int i = +1; data = *ptr; address = &obj; int i = (int) floatNum; int size = sizeof(floatNum); |
right to left |
3 | ->* .* |
Member pointer selector Member pointer selector |
ptr->*var = 24; obj.*var = 24; |
left to right |
4 | * / % |
Multiplication Division Modulus |
int i = 2 * 4; float f = 10 / 3; int rem = 4 % 3; |
left to right |
5 | + - |
Addition Subtraction |
int i = 2 + 3; int i = 5 - 1; |
left to right |
6 | << >> |
Bitwise shift left Bitwise shift right |
int flags = 33 << 1; int flags = 33 >> 1; |
left to right |
7 | < <= > >= |
Comparison less-than Comparison less-than-or-equal-to Comparison greater-than Comparison geater-than-or-equal-to |
if( i < 42 ) ... if( i <= 42 ) ... if( i > 42 ) ... if( i >= 42 ) ... |
left to right |
8 | == != |
Comparison equal-to Comparison not-equal-to |
if( i == 42 ) ... if( i != 42 ) ... |
left to right |
9 | & | Bitwise AND | flags = flags & 42; | left to right |
10 | ^ | Bitwise exclusive OR | flags = flags ^ 42; | left to right |
11 | | | Bitwise inclusive (normal) OR | flags = flags | 42; | left to right |
12 | && | Logical AND | if( conditionA && conditionB ) ... | left to right |
13 | || | Logical OR | if( conditionA || conditionB ) ... | left to right |
14 | ? : | Ternary conditional (if-then-else) | int i = (a > b) ? a : b; | right to left |
15 | = += -= *= /= %= &= ^= |= <<= >>= |
Assignment operator Increment and assign Decrement and assign Multiply and assign Divide and assign Modulo and assign Bitwise AND and assign Bitwise exclusive OR and assign Bitwise inclusive (normal) OR and assign Bitwise shift left and assign Bitwise shift right and assign |
int a = b; a += 3; b -= 4; a *= 5; a /= 2; a %= 3; flags &= new_flags; flags ^= new_flags; flags |= new_flags; flags <<= 2; flags >>= 2; |
right to left |
16 | , | Sequential evaluation operator | for( i = 0, j = 0; i < 10; i++, j++ ) ... | left to right |
若有定义:int t[3][2];,则能正确表示t数组元素地址的表达式是: A t[3] B &t[3][2] C *t[2] D t[2] A.t[3]越界了,C语言数组从0开始. B.也越界了 C.是元素的值 D.正解
楼上正解: 转义符号 当用 转义不了时, 请用@ 如 string str =@" "; 裏面的 换行空格制表位都会失效 char [] mark={'。','!',',','?',' ','/n'} 但是楼主 定义的数组类型是char (单字符), 有且仅有一个字符! 所以当然会报错啊! 换成其他类型行了!
ASCII码表完整版
ASCII值 |
控制字符 |
ASCII值 |
控制字符 |
ASCII值 |
控制字符 |
ASCII值 |
控制字符 |
0 |
NUT |
32 |
(space) |
64 |
@ |
96 |
、 |
1 |
SOH |
33 |
! |
65 |
A |
97 |
a |
2 |
STX |
34 |
” |
66 |
B |
98 |
b |
3 |
ETX |
35 |
# |
67 |
C |
99 |
c |
4 |
EOT |
36 |
$ |
68 |
D |
100 |
d |
5 |
ENQ |
37 |
% |
69 |
E |
101 |
e |
6 |
ACK |
38 |
& |
70 |
F |
102 |
f |
7 |
BEL |
39 |
, |
71 |
G |
103 |
g |
8 |
BS |
40 |
( |
72 |
H |
104 |
h |
9 |
HT |
41 |
) |
73 |
I |
105 |
i |
10 |
LF |
42 |
* |
74 |
J |
106 |
j |
11 |
VT |
43 |
+ |
75 |
K |
107 |
k |
12 |
FF |
44 |
, |
76 |
L |
108 |
l |
13 |
CR |
45 |
- |
77 |
M |
109 |
m |
14 |
SO |
46 |
. |
78 |
N |
110 |
n |
15 |
SI |
47 |
/ |
79 |
O |
111 |
o |
16 |
DLE |
48 |
0 |
80 |
P |
112 |
p |
17 |
DCI |
49 |
1 |
81 |
Q |
113 |
q |
18 |
DC2 |
50 |
2 |
82 |
R |
114 |
r |
19 |
DC3 |
51 |
3 |
83 |
X |
115 |
s |
20 |
DC4 |
52 |
4 |
84 |
T |
116 |
t |
21 |
NAK |
53 |
5 |
85 |
U |
117 |
u |
22 |
SYN |
54 |
6 |
86 |
V |
118 |
v |
23 |
TB |
55 |
7 |
87 |
W |
119 |
w |
24 |
CAN |
56 |
8 |
88 |
X |
120 |
x |
25 |
EM |
57 |
9 |
89 |
Y |
121 |
y |
26 |
SUB |
58 |
: |
90 |
Z |
122 |
z |
27 |
ESC |
59 |
; |
91 |
[ |
123 |
{ |
28 |
FS |
60 |
< |
92 |
/ |
124 |
| |
29 |
GS |
61 |
= |
93 |
] |
125 |
} |
30 |
RS |
62 |
> |
94 |
^ |
126 |
~ |
31 |
US |
63 |
? |
95 |
— |
127 |
DEL |
NUL 空 |
VT 垂直制表 |
SYN 空转同步 |
SOH 标题开始 |
FF 走纸控制 |
ETB 信息组传送结束 |
STX 正文开始 |
CR 回车 |
CAN 作废 |
ETX 正文结束 |
SO 移位输出 |
EM 纸尽 |
EOY 传输结束 |
SI 移位输入 |
SUB 换置 |
ENQ 询问字符 |
DLE 空格 |
ESC 换码 |
ACK 承认 |
DC1 设备控制1 |
FS 文字分隔符 |
BEL 报警 |
DC2 设备控制2 |
GS 组分隔符 |
BS 退一格 |
DC3 设备控制3 |
RS 记录分隔符 |
HT 横向列表 |
DC4 设备控制4 |
US 单元分隔符 |
LF 换行 |
NAK 否定 |
DEL 删除 |
0~32及127(共34个)是控制字符或通讯专用字符(其余为可显示字符),如控制符:LF(换行)、CR(回车)、FF(换页)、DEL(删除)、BS(退格)、BEL(振铃)等;通讯专用字符:SOH(文头)、EOT(文尾)、ACK(确认)等;ASCII值为 8、9、10 和 13 分别转换为退格、制表、换行和回车字符。它们并没有特定的图形显示,但会依不同的应用程序,而对文本显示有不同的影响。 33~126(共94个)是字符,其中48~57为0到9十个阿拉伯数字;
65~90为26个大写英文字母,97~122号为26个小写英文字母,其余为一些标点符号、运算符号等。
C语言中下列选项中,非法的字符常量是() A) ' ' B) '17' C) " " D)'xaa' 语言中 字符有两种表示表示 一种是单个字符 'a' ','等 另一种是用开始的转义字符 比如‘\' ' ' 这些有特定含义 还有一些字符不能用上述方式表示 此时'123' 这个表示asc码为123的字符 因为C语言整数有几种表示表示方式 123的8进制为0153 123的16进制为 x7B 所以'123'和'