UMBC CMSC 201 Fall '06 CSEE | 201 | 201 F'06 | lectures | news | help Search Notes:

# Another Pointer Example

```int a, b;
int *ptr1, *ptr2;  /* Declare 2 pointers to int,    */
/* ptr1 and ptr2                 */

a = 1;
b = 2;

ptr1 = &a;        /* ptr1 holds the address of a    */
ptr2 = &b;        /* ptr2 holds the address of b    */

*ptr1 = 11;       /* Put the value 11 into the      */
/* container that ptr1 points to  */

*ptr2 = 22;       /* Put the value 22 into the      */
/* container that ptr2 points to  */

ptr1 = ptr2;      /* Let the variable ptr1 now hold */
/* the same address as ptr2 holds */

*ptr1 = 99;       /* Put the value 99 into the      */
/* container that ptr1 points to  */

ptr1 = &a;        /* ptr1 holds the address of a    */

*ptr1 = *ptr2;    /* Put the value found at the     */
/* address that ptr2 points to    */
/* into the container that ptr1   */
/* points to.                     */
```

CSEE | 201 | 201 F'06 | lectures | news | help

Tuesday, 22-Aug-2006 07:14:18 EDT