From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Passing pointers to functions - C Tutorial
From the course: Complete Guide to C Programming Foundations
Passing pointers to functions
- [Instructor] When you pass a pointer to a function, you're passing an address either directly or as a memory location stored in a pointer. A function that accepts a pointer as input, accepts an address. In this exercise file, the doubler function consumes the address of an integer variable, an integer pointer referenced as alpha within the function. You see the contents of the address are manipulated. The asterisk operator dereferences the address. In this instance, the integer value at location alpha is doubled. Nothing is returned from this function, it's a void data type. Nothing needs to be returned as memory is manipulated directly. In the main function, the address of variable a is passed at line 13. Only the address, not the value, which is assigned is 25, run. The value is modified without being returned. That's because the address passed references the value, which is modified in memory. At line 13, the address of variable a is passed to the function. The ampersand operator…
Contents
-
-
-
-
-
-
-
-
-
-
Understanding pointers3m 23s
-
(Locked)
Using pointers to manipulate data2m 53s
-
(Locked)
Doing pointer math3m 10s
-
(Locked)
Comparing arrays and pointers5m 5s
-
(Locked)
Challenge: Output a string57s
-
(Locked)
Solution: Output a string2m 44s
-
(Locked)
Allocating storage3m 42s
-
(Locked)
Working with a pointer array4m
-
(Locked)
Using pointers in structures3m 8s
-
(Locked)
Challenge: Allocating structures1m 3s
-
(Locked)
Solution: Allocating structures3m 34s
-
(Locked)
Passing pointers to functions2m 23s
-
(Locked)
Returning pointers from a function2m 31s
-
Chapter challenge: Processing input1m 26s
-
(Locked)
Chapter solution: Processing input3m 14s
-
-
-
-