Memset () function in C
The function void * memset (void * str, int c, size_t n) copies the character c (an unsigned char) to the first n characters of the string pointed to by parameter str.
The function void * memset (void * str, int c, size_t n) copies the character c (an unsigned char) to the first n characters of the string pointed to by parameter str.
Declare memset () in C
Below is the declaration for memset () in C:
void * memset ( void * str , int c , size_t n )
Parameters
str - This is a pointer to memory block to fill .
c - This is the value to be set. The value is passed as an int, but the memory fill function uses the unsigned char conversion of this value.
n - This is the number of bytes to be set to the value.
Returns the value
This function returns a pointer to memory str.
For example
The following program C illustrates the usage of memset () in C:
#include #include int main () { char str [ 50 ]; strcpy ( str , "Hoc C co ban va nang cao tai QTM" ); puts ( str ); memset ( str , '$' , 7 ); puts ( str ); return ( 0 ); }
Compile and run the above C program to see the results.
According to Tutorialspoint
Previous article: memmove function in C
Next lesson: strcat function in C
4 ★ | 5 Vote
You should read it
- The strrchr () function in C
- Strcpy () function in C
- Memmove function in C
- Function strxfrm () in C
- The strcoll () function in C
- The function strcmp () in C
- The function strncmp () in C
- The strstr () function in C
- The function strpbrk () in C
- The strtok () function in C
- Strcat function in C
- The strlen () function in C
Maybe you are interested
Traveling with Kids: How to Make Your Trip Fun and Stress-Free
Instructions for recording live video on ChatGPT Voice
One Piece: Strength Ranking of Straw Hat Crew Members
Instructions for inserting stickers into photos on iPhone
FBI Warns iMessage Is Not a Strongly Encrypted Messaging App
Google Labs Releases Whisk: A Tool That Allows You to Upload Images as Instructions Instead of Text Prompts