Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Pascal

Idiom #284 Create a zeroed list of integers

Create a new list a (or array, or slice) of size n, where all elements are integers initialized with the value 0.

a := nil;
setlength(a, n);

First clear the array, then set its length. This ensures data is zero-ed.
#include <stdlib.h>
int *a = calloc(n, sizeof(*a));

calloc automatically sets every byte allocated to 0.

New implementation...