小编vip*_*lnj的帖子

数组未正确传递

我尝试发送到被调用函数的数组未正确发送.假设我在数组'a'中插入了五个元素,并使用函数insert函数传递数组,并使用以下代码的最后两行检查数组的大小,它显示的数字小于数组的实际大小.为什么会这样?

void main()
{
    //rest of the code     
    insert(a,key);   //user-defined function
}

void insert(int a[],int key)
{
    int *p=a;
    int n = sizeof(a);
    printf("No. of elements entered:%d\n",n);
}
Run Code Online (Sandbox Code Playgroud)

c arrays

2
推荐指数
1
解决办法
61
查看次数

为什么程序不继续

以下程序是一个递归程序,用于检查数组中的重复条目.程序编译没有错误,但是在我输入命令行参数并按Enter后,它不会继续.光标只是闪烁!它也不会返回任何运行时错误!如果有人解释为什么会这样,那将非常有帮助!谢谢!:)

import java.io.*;
    class RepeatEntries_Recursive
    {
        static int i=0,flag=0;
        public static void main(String[] args) throws IOException
        {
            int[] inp = new int[6];
            for(int k=0;k<args.length;k++)
                inp[k] = Integer.parseInt(args[k]);
            boolean hasItRepeated = Repeating(inp,i);
            if(hasItRepeated == true)
                System.out.println("\nYes, there are entries that repeat in the array!");
            else
                System.out.println("\nNo, entries don't repeat in the array");
        }
        static boolean Repeating(int[] inp,int i)
        {
            for(int j=0;j<inp.length;j++)
            {
                if(inp[i] == inp[j])
                    flag = 1;
                while(i<inp.length-1)
                    Repeating(inp,i+1);
            }
            if(flag==1)
                return true;
            else
                return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

java recursion command-line-arguments

0
推荐指数
1
解决办法
71
查看次数

标签 统计

arrays ×1

c ×1

command-line-arguments ×1

java ×1

recursion ×1