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 - C Tutorial
From the course: Master C Language Pointers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Understanding pointers to pointers4m 32s
-
(Locked)
Sending a pointer to a function3m 36s
-
(Locked)
Sorting pointers2m 6s
-
(Locked)
Managing memory3m 56s
-
(Locked)
Creating pointers to functions2m 30s
-
(Locked)
Challenge: Manipulate a pointer array1m 18s
-
(Locked)
Solution: Manipulate a pointer array3m 20s
-
(Locked)