Concept

How do you pass an array of pointers to structures to a function?

ComputerScienceOne / Passing Arrays of Structures

"Nevertheless, as we’ve previously seen it is sometimes preferable to maintain an array of pointers to structures. If we had an array of pointers, we would have a function that looks something like the following.\n\n/**\n\n* Computes the average GPA of the Student structures in\n\n* the given roster (which is of size n).\n\n*/\n\ndouble computeAverageGpa(const Student **roster, int n) {\n\ndouble sum = 0.0;\n\nint i;\n\nfor(i=0; i<n; i++) {\n\nsum += roster[i]->gpa;\n\n}\n\nreturn sum / n;\n\n}\n\nThe only difference here is in how we access the gpa member variable using the arrow operator instead of the dot operator."

Related Ideas

How do you pass an array of pointers to structures to a function? | ComputerScienceOne | Bifalgorithm | Bifalgorithm