풀이 보관함
[C++] memset(), fill(), fill_n() (메모리 초기화 함수, 사용 방법) 본문
memset()
https://en.cppreference.com/w/cpp/string/byte/memset
- 메모리 변화가 있는건 fill() 권유 하고 있다. (위에 글 읽기)
- 1 byte 단위씩 초기화 하기 때문에 0, false, NULL로 초기화 할 때만 사용해야 한다.
2차원 배열 초기화 방법
#include <memory.h>
bool visited[22][33];
std::memset(visited, false, sizeof(visited));
fill()
https://en.cppreference.com/w/cpp/algorithm/fill
- memset과 달리 자료형의 제약이 없는 편
초기화 사용 방법
std::fill(arr,arr+5,0); //배열, 배열+범위 값, 초기화 값
fill_n()
https://en.cppreference.com/w/cpp/algorithm/fill_n
초기화 사용 방법
std::fill_n(arr, 100, 0) // 배열, 초기화할 원소 개수, 초기화 값
🔗 더 자세하고 한글로 정리 잘 된 블로그 글 소개