要打印数组值(如果为零且在零之后) [英] To print the array value if it zero and after zero

查看:97
本文介绍了要打印数组值(如果为零且在零之后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
main()
{
    int a[]={3,5,4,0,-1,-4,1};
    fun(a);
}
    fun(int *a)
    {
    while(*a++!='\0')
    {
    printf("%d\n",*a++);
    }
}

推荐答案

我看不到任何需要解决"的东西吗?

您的问题是什么?你不懂代码吗?我假设这是家庭作业,为什么不与老师交谈?
I don''t see anything that needs to be ''slove''d ?

What is your question, do you have one ? Do you not understand the code ? I assume it''s homework, why not talk to the teacher ?


您将两个变量传递给函数,而该函数只接受一个? ??也有其他错误.您的C编译器将为您提供更好的帮助.
You pass two variables to function whereas the function accepts only one? Huh? There are other errors too. Your C compiler will help you better.


一旦您的while循环达到值0,它就会爆发.如果要打印包括所有零在内的所有值,则需要在末尾找到一个不同的标记,或者将数组的长度传递给函数.与整数进行比较时,也不应使用常量''\0''(它是空字符).整数零的正确值为0.
As soon as your while loop gets to the value 0 it will break out. If you want to print all values including any zeroes then you need to find a different marker for the end, or pass the length of the array to your function. Also you should not use the constant ''\0'' (which is the null character) when comparing against an integer; the correct value for integer zero is 0.


这篇关于要打印数组值(如果为零且在零之后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆