gcc 4.4.4 c89
我只是在试验一个int数组.我想到了一些东西.我可以终止它吗?例如,我使用0到nul终止.但是,0可能是此数组中的有效值.
下面的代码将在5之后终止.尽管我的意思是0是有效数字.但是,我可以指定数组的大小.但在这种情况下,我不想这样做,因为我只对这个特殊问题感兴趣.
非常感谢任何建议,
#include <stdio.h>
static void test(int *p);
int main(void)
{
int arr[] = {30, 450, 14, 5, 0, 10, '\0'};
test(arr);
return 0;
}
static void test(int *p)
{
while(*p) {
printf("Array values [ %d ]\n", *p++);
}
}
Run Code Online (Sandbox Code Playgroud) c ×1