这里的写法,可以避免使用 for 循环,减少栈空间内存的使用和减少运行时的计算开销!
#
include
iostream>
#include
string>
using
namespacestd;
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
}
}以上就是C/C++中用空指针简化代码实例的详细内容,更多请关注php中文网其它相关文章!
c++怎么学习?c++怎么入门?c++在哪学?c++怎么学才快?不用担心,这里为大家提供了c++速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号