C++ memset()

1 개요[ | ]

C++memset()

2 char배열[ | ]

#include <iostream>
#include <cstring>
using namespace std;

int main() {
    char str[] = "hello world";
    memset(str, '*', 5);
    cout << str; // ***** world
}

3 int배열[ | ]

#include <iostream>
#include <cstring>
using namespace std;
int main() {
    int nums[] = {1,2,3,4};
    for(auto n: nums) cout << n << ' '; // 1 2 3 4 
    cout << '\n';
    
    memset(nums, 0, sizeof(nums));
    for(auto n: nums) cout << n << ' '; // 0 0 0 0 
}

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}