0
How to work with a structure array using pointer?
5 ответов
+ 1
George pass the array normally to the function. Your array variable is actually a pointer that points to the first element of the array. To prove that I made this program below, if arr wasn’t a pointer then the outputs would both be 1 2 3
https://code.sololearn.com/c6NT8CThwt95/?ref=app
+ 1
- Throughout the code you use the Student struct as an array by indexing it but it is not an array so it confuses C. I think you want an array of students which in that case just declare one with the type of Student.
- When displaying the student name you used . on a pointer pointing to a struct instead of ->
- I'm also not sure why you use for loops that will always run only once - why not just remove them?
Changes:
https://code.sololearn.com/c2L75k5tIJfR/?ref=app
0
Turtle shell, thanks for your suggestions, I used for loop because I have to take the data(inputs) from several students not one however here on solo Learn we are restricted to give input only once.
0
Turtle shell, is it possible that I pass an array structure variable to a pointer in a function in which I can make further update to the data?
0
Thank you very much, turtle shell. Your code was helpful in understanding how pointers really work. 😊