Is there any limit(members) during array initialization to the value 0

IN ARRAY INITIALIZATION, IF WE USE int arr[10]={};
THEN ALL THE MEMBERS OF ARRAY ARE ASSIGNED TO VALUE ‘0’.

In this code
If I use ll b[100001]={}, then this code is not working.
When I’m using memset (b,0,sizeof(b)), this code is working.

Problem Link

My Working Code
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define f(i,n) for(int i=0;i<n;i++)
using namespace std;

ll b[100001];

ll find(ll a[],ll i,ll n)
{
if(i==n-1)
return b[i]=1;
if(b[i]!=0)
return b[i];
if(a[i]*a[i+1]<=0)
return b[i]=1+find(a,i+1,n);
else
return b[i]=1+(find(a,i+1,n))*0;
}

void solve()
{
ll n;
memset(b,0,sizeof(b));
cin>>n;
ll a[n];
f(i,n)
{
cin>>a[i];
}
find(a,0,n);
f(i,n)
cout<<b[i]<<’ ‘;
cout<<’\n’;
}
int main() {
speed

int test;
cin>>test;
while(test--)
{
    solve();
}
return 0;

}

When you use b[100001]={} you are inititalising all elements with the value of 0. But after the first test case you are modifying its elements and therefore the elements are no longer 0. In the second case you are assigning the value of 0 in each test case and thus it works.

PS: Global arrays are initialised with 0 already.

3 Likes