{"revision": {"id": "f3abcbf0-2f95-11f1-9466-e86a64d24d78", "node_id": "f3aadc3e-2f95-11f1-98f8-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "cpp Pointers\r\n==============\r\n\r\n**if p is a pointer**\r\n\r\n&p\r\n the memory address of p\r\n\r\n\\*p\r\n  the content that p points to\r\n\r\np\r\n the content of p (or the address that p points to)\r\n\r\nDynamic memory allocation or alias\r\n------------------------------------------\r\n\r\n**Useful but dangerous...**\r\n\r\n.. code-block:: cpp\r\n\r\n int *p, *q; // create two pointers, named p and q\r\n \r\n p = new int; // \r\n\r\n *p = 100;\r\n\r\n q = p;\r\n\r\n *q = 200;\r\n\r\n q = new int;\r\n\r\n *q = *p;\r\n\r\n delete p; // give memory that p occupied back to operating system\r\n\r\n p = NULL; // set p to memory address 0  \r\n\r\n delete q; // give memory that q occupied back to operating system\r\n\r\n q = NULL; // set q to memory address 0\r\n\r\n\r\n\r\nDynamic Allocation for arrays\r\n--------------------------------------------\r\n\r\n.. code-block:: cpp\r\n\r\n int size = 5; // create an integer\r\n int *A;       // create an array of pointers\r\n\r\n A = new int[ size ] \r\n\r\n", "source_format": "rst", "revision_number": 8, "created": 1317066901000}}