Why isn't memset assigning 1?

Viewed 2134
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int color[1001][1001];

int main() {
    int i, j;
    memset(color, 1, sizeof(color[0][0]) * 2 * 2);
    for(i = 0; i < 4; i++) {
        for(j = 0; j < 4; j++) {
            printf("%d ", color[i][j]);
        }
        printf("\n");
    }
    printf("\n");

    return 0;
}

output:

16843009 16843009 16843009 16843009 
0 0 0 0 
0 0 0 0 
0 0 0 0 

Why isn't it assigning 1? Why didn't it print 1 instead of 16843009 ? How can i assign integer 1?

But if i write memset(color, 0, sizeof(color[0][0]) * 2 * 2); Then the output:

0 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 

Why is this?

Any answer will be highly appreciated. Thanks in advance.

4 Answers
Related