Expert C Programming

(Jeff_L) #1

int (result)[20]; / declare a pointer to 20-int


array */


...


result = paf(); / call the function /


(result)[3] = 12; / access the resulting array */


Or wimp out, and use a struct:


struct a_tag {


int array[20];


} x,y;


struct a_tag my_function() { ... return y }


which would also allow:


x=y;


x=my_function();


at the expense of having to use an extra selector x in accessing the elements:


x.array[i] = 38;


Make sure you don't return a pointer to an auto variable (see Chapter 2 for more details).


Handy Heuristic


Why Does a Null Pointer Crash printf?


One question that gets asked over and over again is, "Why does a null pointer argument to
printf crash my program?" People seem to want to write code like this:


char *p = NULL;


/... /


printf("%s", p );


and not have it crash. Customers sometimes complain, "It doesn't crash when I do that on

Free download pdf