Segmentation fault is coming could u tell me whats wrong in this code

you have to do some changes in your code

  1. use long long int instead of int

  2. data type of p array should be bool not int as you are storing 0 and 1 only

  3. The 500000th prime is 7368787
    roughly 74*10^5

do all these changes and then try

https://ide.codingblocks.com/s/329974 still error is coming

you have to do this at
for(int j=i*i;j<n;j+=i){
and you have not done it

because here you are squaring i i and go till 10^5 whose square will overflow the int and cause segmentation fault

https://ide.codingblocks.com/s/329989 i did their also sir still error i coming

there are many mistakes in your code
even your sieve function is not correct

i have done all the changes
you can see them in modified code below

Modified Code