C/C++运算符的优先级
Precedence Operator Description Example Overloadable Associativity
1
::
Scope resolution operator
Class::age = 2;
no
none
2
()
()
[]
->
.
++
--
const_cast
dynamic_cast
static_cast
reinterpret_cast
typeid
Function call
Member initalization
Array access
Member access from a pointer
Member access from an object
Post-increment
Post-decrement
Special cast
Special cast
Special cast
Special cast
Runtime type information
isdigit('1')
c_tor(int x, int y) : _x(x), _y(y*10){};
array[4] = 2;
ptr->age = 34;
obj.age = 34;
for( int i = 0; i < 10; i++ ) cout << i;
for( int i = 10; i > 0; i-- ) cout << i;
const_cast<type_to>(type_from);
dynamic_cast<type_to>(type_from);
static_cast<type_to>(type_from);
reinterpret_cast<type_to>(type_from);
cout « typeid(type).name();
yes
yes
yes
yes
no
yes
yes
no
no
no
no
no
left to right
3
!
not
~
compl
++
--
-
+
*
&
new
new []
delete
delete []
(type)
sizeof
Logical negation
Alternate spelling for !
Bitwise complement
Alternate spelling for ~
Pre-increment
Pre-decrement
Unary minus
Unary plus
Dereference
Address of
Dynamic memory allocation
Dynamic memory allocation of array
Deallocating the memory
Deallocating the memory of array
Cast to a given type
Return size of an object or type
if( !done ) …
flags = ~flags;
for( i = 0; i < 10; ++i ) cout << i;
for( i = 10; i > 0; --i ) cout << i;
int i = -1;
int i = +1;
int data = *intPtr;
int *intPtr = &data;
long *pVar = new long;
MyClass *ptr = new MyClass(args);
delete pVar;
delete [] array;
int i = (int) floatNum;\\int size = sizeof(float);
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
right to left
4
->*
.*
Member pointer selector
Member object selector
ptr->*var = 24;
obj.*var = 24;
yes
no
left to right
5
*
/
%
Multiplication
Division
Modulus
int i = 2 * 4;
floa
相关文档:
整型常量就是整常数。使用的整常数有八进制、十六进制和十进制三种。 十进制整常数不能有前导0,不能有非数字字符。 八进制整常数必须以0开头,不能有非数字字符。 十六进制整常数必须一0X或0x开头,不能有非法字母( ......
栈:函数调用的时候,在栈中保存局部变量和函数参数等。当函数返回时,自动清除栈。
自由存储区:也称为堆(heap),可以看作大量的内存段。通过 new 操作符分配的内存在堆中。程序结束之前不自动清除自由存储区。需要由程序来负责释放(delete)。
1.
对指向栈上内存的指针调用delete会导致程序Crash。
2.
new 进 ......
void StraightSelectionSort(int array[], unsigned int n)
{
/*
注:关键字值类型为int,数组的索引是从0开始
1. 初始状态无序区为array【0, n - 1】,有序区为空。
2. 第1趟排序从array【0, n - 1】中找到下标为k的关键字最小值,把array【k】和
array【0】交换。现在无序区为array【1, n - 1】, 有序区 ......