memset allows you to fill in individual bytes as memory, and you are trying to set integer values ββ(maybe 4 or more bytes). Your approach will only work with numbers 0 and -1 , since they are both represented in binary format as 00000000 or 11111111 .
The for loop doesn't bother too much:
int main() { int i, val = 1, max = 4; int array[max][max]; max = max * max; for(i = 0 i < max; i++) { array[i] = val; } }
source share