Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zero an array in C code [duplicate]

Tags:

arrays

c

Possible Duplicates:
How to initialize an array to something in C without a loop?
How to initialize an array in C

How can I zero a known size of an array without using a for or any other loop ?

For example:

arr[20] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0; 

This is the long way... I need it the short way.

like image 635
Batman Avatar asked Apr 12 '11 13:04

Batman


People also ask

How do you replace duplicates in an array?

To remove duplicates from an array: First, convert an array of duplicates to a Set . The new Set will implicitly remove duplicate elements. Then, convert the set back to an array.

How do you remove duplicate values from an array?

We can remove duplicate element in an array by 2 ways: using temporary array or using separate index. To remove the duplicate element from array, the array must be in sorted order. If array is not sorted, you can sort it by calling Arrays. sort(arr) method.


1 Answers

int arr[20] = {0}; 

C99 [$6.7.8/21]

If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.


like image 127
Prasoon Saurav Avatar answered Sep 26 '22 21:09

Prasoon Saurav