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.
in the code there are two steps to acquire a new array filled with zeroes:
At first step the allocation itself: int *a=(int )malloc(sizeof(int)(n+1));
Second step is to propagate zero values using for-loop upon newly created array.
In my opinion, we can do the same with single call of "calloc". It supposed to be faster in theory, cause calloc is hardware dependent and probably we don't have to loop over N items again just for get them zero valued, since calloc could know is it actually required or not, so on some harware it could be already zeroes or hardware knows better how to zero during allocation faster
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
in the code there are two steps to acquire a new array filled with zeroes:
In my opinion, we can do the same with single call of "calloc". It supposed to be faster in theory, cause calloc is hardware dependent and probably we don't have to loop over N items again just for get them zero valued, since calloc could know is it actually required or not, so on some harware it could be already zeroes or hardware knows better how to zero during allocation faster