Q:

To find the frequency of a number in an array using recursion

My code blocks is giving an error.But i'm not able to find it anywhere in the
program.  it's saying

in Line 3 :expected ';',',' or ')' before '=' token

 #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;
 }

A:

In C, you cannot assign a default value in function parameter.
Remove =0 in
  int count_key1(int a[],int size,int key,int flag=0)

IIRC, you got confused with C++ function overloading, where, we can have some default value to a parameter, if the argument is not passed while calling the function.
However, in C, a function call has to match exactly the signature present in the definition. So, basically, there is no need for a default value to be present at function definition, as such.

