We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The default code doesn't malloc the total_number_of_books and total_number_of_pages for you. It just declares them in the global space. So you have to do that first before doing the query==1 section.
I used the more esoteric notation for pointers, but array style also works (and is easier to understand). So total_number_of_pages[x][total_number_of_books[x-1]]=y; is also legit. The reason the x-1 is used instead of x is because, while they pass in the books according to their index value (0 instead of 1), they perform the queries by the actual physical amount of books (1 instead of 0).
Dynamic Array in C
You are viewing a single comment's thread. Return to all comments →
The default code doesn't malloc the total_number_of_books and total_number_of_pages for you. It just declares them in the global space. So you have to do that first before doing the query==1 section.
I used the more esoteric notation for pointers, but array style also works (and is easier to understand). So
total_number_of_pages[x][total_number_of_books[x-1]]=y;
is also legit. The reason the x-1 is used instead of x is because, while they pass in the books according to their index value (0 instead of 1), they perform the queries by the actual physical amount of books (1 instead of 0).