Getting runtime error , please help me find error


#1

Blockquote

vector Solution::primesum(int A) {
bool prime[A+2];
vector vec;
memset(prime, true, sizeof(prime));
prime[0]=prime[1]=false;
for(int i=2;ii<=A;i++){
if(prime[i]==true){
for(int j=i
i;j<=A;j+=i){
prime[j]=false;
}
}
}
if(prime[A-2]==true){
vec.push_back(2);
vec.push_back(A-2);
return vec;
}
else{
int j;
for(int i=3;i<=j;i++){
j=A-i;
if(prime[i]==true && prime[j]==true){
vec.push_back(i);
vec.push_back(j);
return vec;
}
}
}
}

Blockquote


#2

I think it is because in the else block you declared variable j and in the next line in the loop you are using it in the for loop condition without initializing it.