PracticeDev/study_cpp/memset/memset_char_test.cpp

15 lines
391 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <memory.h> //我试了一下C语言这么用C++还可以用<cstring>
#include <stdio.h>
int main( void )
{
char buffer[] = "This is a test of the memset function";
printf( "Before: %s\n", buffer );
memset( buffer, '*', 4 );
printf( "After: %s\n", buffer );
memset( buffer, '*', sizeof(buffer) );
printf( "After: %s\n", buffer );
return 0;
}