Expert C Programming

(Jeff_L) #1

Programming Solution


Playing Around with Array/Pointer Arguments


char ga[] = "abcdefghijklm";


void my_array_func( char ca[10] )


{


printf(" addr of array param = %#x \n",&ca);


printf(" addr (ca[0]) = %#x \n",&(ca[0]));


printf(" addr (ca[1]) = %#x \n",&(ca[1]));


printf(" ++ca = %#x \n\n", ++ca);


}


void my_pointer_func( char *pa )


{


printf(" addr of ptr param = %#x \n",&pa);


printf(" addr (pa[0]) = %#x \n",&(pa[0]));


printf(" addr (pa[1]) = %#x \n",&(pa[1]));


printf(" ++pa = %#x \n", ++pa);


}


main()


{


printf(" addr of global array = %#x \n",&ga);


printf(" addr (ga[0]) = %#x \n",&(ga[0]));


printf(" addr (ga[1]) = %#x \n\n",&(ga[1]));


my_array_func( ga );


my_pointer_func( ga );


}


And the output is:


% a.out


addr of global array = 0x20900


addr (ga[0]) = 0x20900


addr (ga[1]) = 0x20901


addr of array param = 0xeffffa14


addr (ca[0]) = 0x20900

Free download pdf