I was solving a problem from a CodeChef contest Link to the problem, when I came across this error. My code was:
#include <stdio.h>
int main(void) {
int t;
scanf("%d",&t);
while(t--)
{
int n;
int max=0;
int count=0;
int a[n];
int b[n];
scanf("%d",&n);
for(int j=0;j<n;j++)
{
scanf("%d",&a[j]);
}
for(int k=0;k<n;k++)
{
scanf("%d",&b[k]);
}
for(int x=0;x<n;x++)
{
if(a[x]&&b[x]!=0)
{
count=count+1;
}
else
{
if(count>max)
{max=count;
count=0;}
}
}
if(count>max)
max=count;
printf("%d", max);
}
return 0;
}
I saw another similar problem on stack which said that the solution was to change the argument of the function but the void argument type in int main was given by the contest website itself so I don't think that should be the problem.
What Jarod42 said solved the question. The problem was just that I did not take input in my length variable n before declaring the arrays a[n] and b[n].Moving the scanf line to just after declaring n seems to work.
Instead of
Thank you everyone for contributing.