Declaration:
int *ptr; /* declare a pointer to an integer */ int i,j, *ptr2; /* declare two integers and a pointer to an integer */ |
int number; ptr = &number; /* address of number assigned to ptr */ |
For example:
int number = 7; int number_2; int *ptr; ... ptr = &number; printf("address of number is %x \n",ptr); /* %x : hexadecimal */ printf("ptr points to the value %d \n", *ptr); /* *ptr : de-ref ptr */ |
address of number is 0x434560 ptr points to the value 7 |
number_2 = *ptr + 5; /* set number_2 value 12 */ *ptr = 80; /* set number to 80 */ |
...previous | up (conts) | next... |