Reputation: 24750
If I have int someArray[100]
that contains items in various elements, how can I reset them all back to 0?
Basic question, I know, but I usually use Objective-C arrays however for this purpose I'm just storing some numbers and want to deal with it "old school."
Upvotes: 8
Views: 38608
Reputation:
You need to set each element to the value you want:
for (int i = 0; i < 100; ++i)
SomeArray[i] = 0;
For the specific case of integers and the value 0, you can also make use of the fact that their bitwise representation is known (all bits are 0), and so you can use memset
:
memset(SomeArray, 0, sizeof(SomeArray));
Upvotes: 15