0

structure using pointer

https://code.sololearn.com/1773/#c we are using pointers for update_course function which is for scanning information but why do we need pointer for printing that data (display_course function)

25th Mar 2020, 6:52 AM
Reiner
Reiner - avatar
2 ответов
+ 2
We don't need a pointer for displaying the data. Check the code again, they haven't used a pointer for displaying the data. They have just used that . operator for accessing and then printing the data Edit: Here's an explanation If you pass the struct variable as an argument to the function, it will be passed by value, that is, a copy of the struct will be passed. So if you make changes to the values, the changes will be made to the copy of the struct and not the struct variable itself. But if you pass a pointer to the function, you can directly make changes to the memory location of the struct variable. Also, if you want, you can also print the values of the struct with a pointer argument. Edit 2: There is a problem I can't recognize in the above code. It might be that it is not taking the language as C. Just copy the code and run it yourself
25th Mar 2020, 7:06 AM
XXX
XXX - avatar
0
thank you now i got the right answer.
25th Mar 2020, 7:55 AM
Reiner
Reiner - avatar