How to work with a structure array using pointer? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to work with a structure array using pointer?

https://code.sololearn.com/chylR83DkMLQ/?ref=app

26th Mar 2019, 7:19 PM
George
George - avatar
5 Answers
+ 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
27th Mar 2019, 3:42 PM
TurtleShell
TurtleShell - avatar
+ 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
26th Mar 2019, 8:02 PM
TurtleShell
TurtleShell - avatar
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.
27th Mar 2019, 1:02 PM
George
George - avatar
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?
27th Mar 2019, 1:05 PM
George
George - avatar
0
Thank you very much, turtle shell. Your code was helpful in understanding how pointers really work. 😊
27th Mar 2019, 7:46 PM
George
George - avatar