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 create and use an array of structures in C?ComputerScienceOne · Arrays of Structures
- How are arrays passed to functions in C?ComputerScienceOne · Using Arrays with Functions
- How can an array of structure pointers make swapping structures more efficient?ComputerScienceOne · Arrays of Structures
- How can you combine contiguous structure storage with indirect access?ComputerScienceOne · Arrays of Structures
- What is 355 24?ComputerScienceOne · Passing Arrays of Structures . . . . . . . . . . . . . . . . . . . . .