0
structure using pointer
https://code.sololearn.com/crYS56nm3N6P/#c couldnt print the input values correct the places i have made mistakes
4 Respostas
+ 4
The mistake was that you used tem->value for printing instead of tem[i].value. Therefore you only printed the first element of the temp array. And because you used i=1 in the for loops you did start with the second element of temp. This means that the first element stayed untouched but you only printed the first element. Therefore the code didn't work at all.
Here's a fixed version:
https://code.sololearn.com/cj8jIrePkE1q/?ref=app
P. S. i shouldn't be a global variable but defined in the for loop like this:
for (int i = 0; i < n; ++i) { .... }
+ 4
reiner A yes it is right that there's no rule to start with 0. But in this case not starting with 0 made it harder to debug. Also starting with 1 will make one array element unused and therefore waste memory. An array with 10 elements will just provide 9 if you start at 1. That's why almost every programmer starts at 0.
+ 1
i made a miskate "tem->name" here only
i=1 also works fine no issues on that, there is no rule to start with '0'
+ 1
thanks for such a clarification will go through it