lst la danh sach can sap xep
http://stackoverflow.com/questions/228181/the-zen-of-python
Blog này Long không còn dùng nữa. Mời mọi người sang thăm nhà mới tại www.NguyenVuLong.com. Xin cảm ơn
1
2
| int *pnValue = new int;pnValue = new int; // old address lost, memory leak results |
1
2
3
| int nValue = 5;int *pnValue = new int;pnValue = &nValue; // old address lost, memory leak results |
1
2
| int *pnValue = new int;int *pnOtherValue = 0; // will allocate later |
1
2
3
4
5
6
7
| int *pnValue = new int;*pnValue = 7;delete pnValue;pnValue = 0;if (pnValue) *pnValue = 5; |
int *const pnPtr;int *const pnPtr = &value (con trỏ hằng - địa chỉ nó trỏ đến không thể thay đổi) const int *pnPtr = &value (con trỏ này trỏ đến 1 hằng số - và giá trị của con trỏ là không thể thay đổi)
Cụ thể là :
1
2
| int nValue = 5;int *const pnPtr = &nValue; |
intnValue2 = 6 (khai báo 1 biến Integer có địa chỉ khác với địa chỉ của pnPtr)
pnPtr = &nValue (không được phép)*pnPtr = nValue2 (được phép)
1
2
| int nValue = 5;const int *pnPtr = &nValue; |
*pnPtr = nValue2 (không được phép) pnPtr = &nValue (được phép)
const int *const pnPtr = &nValue;
1
2
3
| int nValue = 5;int *const pnValue = &nValue;int &rnValue = nValue; |
1
2
3
4
5
6
7
8
| int nValue = 5;void *pVoid = &nValue;// can not dereference pVoid because it is a void pointerint *pInt = static_cast<int*>(pVoid); // cast from void* to int*cout << *pInt << endl; // can dereference pInt |