Example 1 — Basic memset()
Clear a char buffer.
#include <cstring>
#include <iostream>
int main() {
char buf[5];
std::memset(buf, 0, sizeof buf);
buf[0] = 'A';
std::cout << buf << '\\n';
return 0;
} How It Works
- All bytes become 0.
- Setting buf[0] makes a short C-string.
- Print shows A.

