挑战30天C++入门极限:C/C++中利用空指针(NULL),提高程序运行效率
www.nanhushi.com 佚名 不详
//程序作者:管宁 //站点: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循环,减少栈空间内存的使用和减少运行时的计算开销!