使用递归查找数组中数字的频率

Sta*_*der 2 c function parameter-passing

我的代码块给出了错误.但我无法在任何地方找到它

程序.它在说

第3行:在'='标记之前预期';',','或')'

 #include<stdio.h>

 int count_key1(int a[],int size,int key,int flag=0)
 {

     if(size!=0)
         {
             if(a[size-1]==key)
                 count_key1(a,size--,key,flag++);
         }
     else
        return flag;
 }
 int main()
 {
     int b[30]={1,4,2,3,2,6,6,9},key1=9,result;
     result=count_key1(b,8,key1,0);
     printf("%d is %d times present",key1,result);
     return 0;
 }
Run Code Online (Sandbox Code Playgroud)

Sou*_*osh 9

在C中,您无法在函数参数中指定默认值.

删除=0

  int count_key1(int a[],int size,int key,int flag=0)
Run Code Online (Sandbox Code Playgroud)

IIRC,你对C++函数重载感到困惑,如果在调用函数时没有传递参数,我们可以对参数有一些默认值.

但是,在C中,函数调用必须定义中存在的签名完全匹配.因此,基本上,不需要在函数定义中存在默认值,因此.