C++ cstring memset() function
Example
Fill an array with zeroes:
int myNumbers[5] = {10, 20, 30, 40, 50};
memset(myNumbers, 0, sizeof(myNumbers));
for (int i = 0; i < 5; i++) {
cout << myNumbers[i] << "\n";
}
Try it Yourself »
Definition and Usage
The memset()
function writes a specified value into every byte of the specified memory block.
The memset()
function is defined in the <cstring>
header file.
Syntax
memset(void * destination, int value, size_t size);
The size_t
data type is a positive integer.
Parameter Values
Parameter | Description |
---|---|
destination | Required. A pointer to the block of memory to write to. |
value | Required. The value to write into every byte of the memory block. |
size | Required. The size of the memory block measured in bytes. |
Technical Details
Returns: | A void type pointer to the block of memory. |
---|