Concept

How do pointers pass values by reference in C?

ComputerScienceOne / Function Pointers

"int *ptrC = &c;\n\nsum(x, y, ptrC);\n\n//at this point c contains the value 30\n\nswap(&x, &y);\n\n//at this point, the values in x and y have been swapped\n\n// x contains 20 and y contains 10\n\nThis should look familiar. We saw this same syntax when we used scanf() to read input from the standard input. We needed to place an ampersand in front of each variable in order to pass the variable by reference so that scanf() could place the results into the respective memory locations. If the variables had been passed by value, then scanf() would not have been able to manipulate their values. You can also specify functions to return pointers which we discuss in detail in Chapter 20."

Related Ideas

How do pointers pass values by reference in C? | ComputerScienceOne | Bifalgorithm | Bifalgorithm