Pointers

To use strings and arrays, and to have functions change the values of their arguments you must use pointers.

Declaration:
    int *ptr;         /* declare a pointer to an integer */
    int i,j, *ptr2;   /* declare two integers and a pointer to an integer */

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  */
may produce
    address of number is 0x434560
    ptr points to the value 7
and then
    number_2 = *ptr + 5;    /* set number_2 value 12 */
    *ptr     = 80;          /* set number to 80 */


...previousup (conts)next...



About this document:

Produced from the SGML: /home/isd/public_html/_course_crash_in_c/_reml_grp/index.reml
On: 3/3/2003 at 17:43:41
Options: reml2 -i noindex -l long -o html -p multiple