I really can't understand why the belove code gives error. I get this error:
In function 'int* bubble_sort(int*)':
error: no matching function for call to 'swap(int*&, int&, int&)'

May someone please show me the reason?

int* bubble_sort(int arr[]) {
	for(int i=0;i<sizeof(arr);i++){
		for(int j=0;j<sizeof(arr);j++){
			if(arr[i]>arr[j])
				swap(arr, i, j );
			break;
		}
	}
	return arr;
	
}

void swap(int arr[], int i, int j){
	int tmp=arr[i];
	arr[i]=arr[j];
	arr[j]=tmp;
}

> void swap(int arr[], int i, int j
Because this isn't declared as taking 3 references.

> void swap(int arr[], int i, int j
Because this isn't declared as taking 3 references.

Should it?

I'm going assume that you're going to try it it for yourself, in between posting the question and waiting for an answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.