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.

Using pointers as function arguments

Using pointers as function arguments - C Tutorial

From the course: Master C Language Pointers

Start my 1-month free trial

Using pointers as function arguments

- [Instructor] Like any variable type, a pointer can be an argument in a function. In fact the familiar scanf function uses a pointer, a memory address, as its second argument, as shown in this exercise file. The second argument must be a memory location. Either a pointer or any variable prefixed by an ampersand as shown at line 10 with the variable age. The scanf function returns no value. That's because an address has passed. Within the function, the value is set directly, and this is an advantage of a pointer. And it's why the scanf function works and the value can be output here at line 11. I'm going to fib here, but the function works. In this version of the code a pointer is declared at line six. The pointer is assigned to the address of variable age line 9. Then in the scanf function, the pointer is passed itself. No need to prefix this with an ampersand. Because a pointer is a variable that holds a memory…

Contents