![]() ![]() |
|
挑战30天C++入门极限:C/C++中利用空指针(NULL),提高程序运行效率 | |
作者:佚名 文章来源:不详 点击数 更新时间:2008/4/18 14:40:25 文章录入:杜斌 责任编辑:杜斌 | |
|
|
//站点:www.cndev-lab.com //所有稿件均有版权,如要转载,请务必著名出处和作者 #include <iostream> #include <string> using namespace std; void print_char(char* array[]);//函数原形声明 void main(void) { char* test[]={"abc","cde","fgh",NULL};//这里添加一个NULL,表示不指向任何地址,值为0 print_char(test); cin.get(); } void print_char(char* array[]) { while(*array!=NULL) { cout<<*array++<<endl; } } 这里的写法,可以避免使用for循环,减少栈空间内存的使用和减少运行时的计算开销! |
|
![]() ![]() |