In this part, for N = 50000 the result of k = i * i
overflows an int which is the reason for the segfault.
if (sieve[i] == 0)
{
int k = i * i;
while(k <= N)
{
// For each non prime store its lowest prime divisor.
sieve[k] = i;
k += i;
}
}