SIGSEV error in prime palindrome

My solution to the problem PRPALIN. I have spent a lot of time trying to debug this program but for higher numbers I am getting the SIGSEV signal. When I try to run it on local machine for higher values its returning me a segementation fault. I have tried many things some really stupid things like < to <= or similar things but I can’t reach to the answer.

One more problem that I am facing is that in the function void palindrome(long long int a) why the assignment of rev doesn’t take place on array_pp.

    while(x<1000000)
        {
            long long int rev=0;
            long long int p = x;
            while(p>0)
            {
                rev=rev*10+p%10;
                p=p/10;
            }
            if(x==rev)
                if(rev%2!=0)
                {
                    array_pp[k]=rev;
                    k++;
                    printf("%lld",array_pp[k]);//however ,"%lld",rev gives the desired result
                }
           x++;
        }

Either both the problems are interconnected or there’s something about static variables that I am missing.

Algorithm
I compute all the Palindromes starting from the input a. Then calculate those values which are palindromes and prime and then compute the result.
When I am running the program with the palindrome list starting from the number ‘1’ I am getting a TLE with runtime 1.01 sec and when I pass the input as an argument the code fails.

Please help. Also , I need some help as to how can I make my code more bug free because in competitions I wont have this liberty to ask doubts.

Thankyou :slight_smile: :slight_smile:

To know more about SIGSEGV error see here.