From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

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

Passing pointers to functions

Passing pointers to functions - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Passing pointers to functions

- When you pass a pointer to a function you're passing its address, the memory location stored in the pointer. So a function that accepts a pointer is an argument. Accepts a variable's address in memory. In this exercise files, integer variable A is initialized to two at line ten. Its address is passed to the doubler function in line 13. You see the ampersand address of operator. And then, in the function, no value is returned. But within the function, the value at the address is doubled. Build and run. And the value is modified without being returned. That's because the doubler function is able to modify the value indirectly through its address. In this code, pointer A is passed directly to the doubler function at line 15. No ampersand is needed 'cause it's a pointer. Pointers must be initialized before they're used. So variable A is assigned to the address of variable B in line 13. Build and run. And the value is doubled. Passing pointers is one way you can return multiple values…

Contents