N queen problem (segmentation error)

#include< iostream>

using namespace std;

bool isSafe(int board[][10], int i, int j, int n){

for(int row=0; row < i; row++){
	if(board[row][j]==1)
		return false;
}

int x=i;
int y=j;

while(x>=0 && y>=0){
	
	if(board[x][y]==1)
		return false;

	x--;
	y--;
}

x=i;
y=j;
while(x<n && y<n){
	
	if(board[x][y]==1)
		return false;

	x--;
	y++;
}

return true;

}

bool solveNQueen(int board[][10], int i , int n){

if(i==n){

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(board[i][j]==1)
				cout<<"Q"<<" ";
			else
				cout<<"_"<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	return false;
}


//recursive case

for(int j=0;j<n;j++){

	if(isSafe(board,i,j,n)){
		board[i][j]=1;
		bool nextQueenRakhPaye = solveNQueen(board, i+1, n);
		if(nextQueenRakhPaye){
			return true;
		}

		board[i][j]=0;
	}

}

return false;

}

int main(){

int n;
cin>>n;
int board[][10]={0};
solveNQueen(board,0,n);

return 0;

}

this code is working fine for n=4 but showing segmentation fault (core dump) for n =8 . I can’t get the error.

Hey @princeguptaa
Only one minor correction required in main() function

here specify rows as 10 as well , we dont have to mention rows when we pass all the values with which the array has to be initialized like int arr[][2]={1,2,3,4} here it will create 2 rows but in int arr[][2]={0} , ou compiler doesn’t know how many rows req

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.