I would like to ask you about this code
#include <stdio.h>
#include "bit-array.h"
#ifndef BitArray
#define BitArray(array_name, size)\
int size_in_bits = size/sizeof(long);/*thanks to this, it should work on x64*/\
size_in_bits /= 8;/*conversion from bytes to bits*/\
int array_name[size_in_bits];/*declaration of an array*/\
for(int i = 0; i < size_in_bits; i++)/*filling the array by zeros*/\
array_name[i] = 0;\
#endif
int main()
{
BitArray(test, 100);
for(int i = 0; i < 100; i++)
printf("%d\n", test[i]);
return 0;
}
As far as i know, this macro BitArray(array_name, size) (placed in separate header file bit-array.h) should define and fill an array with zeros, then it should print the zeros into terminal. However, it prints some random numbers from memory. I am kinda stuck here. Can you help please?
EDIT: Thanks for all your answers. I must apologize that I forgot to write here one important thing. And that is fact, that in this task this has to be macro with this prototype: BitArray(array_name, size).
size_in_bitsis not 100. and usememsetto clear memory