Converts the value ch to unsigned char and copies it into each of the first n characters of the object pointed to by str. If the object is not trivially-copyable (e.g., scalar, array, or a C-compatible struct), the behavior is undefined. If n is greater than the size of the object pointed to by str, the behavior is undefined.
void* memset( void* str, int ch, size_t n); Parameters str : Pointer to the object to copy the character. ch : The character to copy. n : Number of bytes to copy. Return value : The memset() function returns str, the pointer to the destination string.
We can use memset() to set all values as 0 or -1 for integral data types also. It will not work if we use it to set as other values. The reason is simple, memset works byte by byte.
0 0 0 0 0 -1 -1 -1 -1 -1 84215045 84215045 84215045 84215045 84215045
This article is contributed by Pranav. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- memset() in C with examples
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Maximum absolute difference in an array
- Count the pairs of vowels in the given string
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- Print path from root to all nodes in a Complete Binary Tree
- Count the number of 1's and 0's in a binary array using STL in C++ ?
- Find elements of an Array which are Odd and Even using STL in C++
- Find elements of an array which are divisible by N using STL in C++
- All reverse permutations of an array using STL in C++
- Generics in C++
- Find the longest subsequence of an array having LCM at most K
- Maximum Subarray Sum after inverting at most two elements
- Maximum element in a sorted and rotated array