不要忘记为数组和动态内存赋初值

不要忘记为数组和动态内存赋初值。

防止将未被初始化的内存作为右 值使用。

 

 1 #include <iostream>
 2 #include <string.h>
 3 
 4 //main()函数
 5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 6 using namespace std;
 7 int main(int argc, char** argv) {
 8        //声明字符数组
 9     char string[80],*p;
10 
11     //输入字符串并将其反转
12     cout<<"string:";
13     cin>>string;
14     p=strrev(string );
15     cout<<"p     :"<<p<<endl;
16     cout<<"string:"<<string<<endl;
17     return 0;
18 }

 

posted @ 2018-08-03 13:38  borter  阅读(301)  评论(0编辑  收藏  举报