global or static 배열일 경우 0으로 기본적으로 초기화 됩니다.
int array[100] = {1,}; 이런 식으로 사용할 경우 가장 처음 값만 1로 초기화되고 나머지는 0으로 초기화 됩니다.
local 배열일 경우에는 쓰레기 값으로 초기화가 되어버리니 주의 합니다.
이건 일반 변수인 int c; 와 같은 경우에도 global 혹은 static에서는 자동으로 0으로 초기화 되는 것과 같은 원리 입니다.
배열을 0이 아닌 다른 값으로 초기화 하는 방법
int arr[5];
fill_n(arr,5,1);
int arr[5];
fill(arr,arr+5,1);
#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
int d[100][100];
memset(d, -1, sizeof(d));
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
char a[] = "how to use memmove, let's show!";
memmove(a+15,a+10,5);
cout << a << '\n';
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
char a[] = "how to use memcpy, let's show";
char b[30];
char c[30];
memcpy(b,a,strlen(a)+1);
memcpy(c,"열공!",15);
cout << a << '\n';
cout << b << '\n';
cout << c << '\n';
return 0;
}