From the course: Master C Language Pointers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Sending a pointer to a function

Sending a pointer to a function - C Tutorial

From the course: Master C Language Pointers

Start my 1-month free trial

Sending a pointer to a function

- [Instructor] You can return a pointer from a function, but what about sending a pointer to a function as an argument? First, in this code, an array of pointers is allocated at line 16. Storage for seven character sized pointers is allocated to the week pointer, which is a double pointer shown here at line 13, and the malloc function, which returns the pointer's address, is type cast to a double character pointer as well. Each week day string is manually assigned to the array lines 23 through 29, and then the for loop at line 31 outputs each of the array elements one at a time using pointer notation, build and run. And there are the seven days of the week. Now, the point here is two fold, first to show how an array of pointers can be allocated in an extremely clumsy manner. But more importantly, the memory is allocated in a function and its address is returned, returning an address, or pointer, is valid as shown at…

Contents