帮小弟我看看哪里不对
帮我看看哪里不对?
void test2()
{
char string[10], str1[10];
int i;
for(i=0; i<10; i++)
{
str1[i] = 'a';
}
strcpy( string, str1 );
}
运行可以,为什么?
------解决方案--------------------
void test2()
{
char string[10], str1[10];
int i;
for(i=0; i<10; i++)
{
str1[i] = 'a';
}
strcpy( string, str1 );
}
运行可以,为什么?
------解决方案--------------------
- C/C++ code
// test1.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" void test2() ; int _tmain(int argc, _TCHAR* argv[]) { test2() ; return 0; } void test2() { char string[10], str1[10]; int i; memset(str1,0, 10) ; for(i=0; i <9; i++) { str1[i] = 'a'; } strcpy( string, str1 ); std::cout << string << std::endl ; std::cout << str1 << std::endl ; }