Problem in last line of code

#include <bits/stdc++.h>
using namespace std;

#define ll long long
int main() {
char a[20];
cin>>a;
int len=strlen(a);
ll ans=0ll;
ans=(1<<len)-2;
for(int i=len-1,pos=0;i>=0;i–,pos++)
{
if(a[i] == ‘7’)
{
ans +=(1<<pos);
}
}
cout<<ans+(1<<0)<<endl;
return 0;
}

Sir when i print (ans+1) why it give segmentation fault.
but succesfully run when printing (ans+(1<<0))
Sir please explain me reason for this
why this happen.

@Ankit_kumar_3003 its running fine both the cases you mentioned also passing all the cases

@Ankit_kumar_3003 also running fine on cb ide so dont worry code is correct
dont forget to mark it as resolved :smiley:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.