这里的写法,可以避免使用 for 循环,减少栈空间内存的使用和减少运行时的计算开销!
#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;
}
}
本文介绍了一种在C++中使用零拷贝技术的方法,通过避免显式的for循环来减少栈空间内存的使用和运行时计算开销。具体实现是通过在函数中使用while循环迭代字符数组指针,直到遇到NULL终止符。

被折叠的 条评论
为什么被折叠?



