Hello guys. I am a new member here. I come from greece and C programming is my activate hobbie. Lately I had been trying to implement a simple version of general bubble short algorithm. Finally I managed to run my code but I have some basically and important queries , So could you help me?
The code is given below :
Code:
#include<stdio.h>
#define n 10
void bubble_sort(int x[n]);
int main()
{
int x[n]={2,3,4,5,6,1,7,9,11,2};
int i;
printf("==============");
printf("Before sorting:");
printf("==============");
for(i=0; i<n; i++)
printf("\n %d " , x[i]);
puts("\n");
printf("===============");
printf("After sorting: ");
printf("===============");
bubble_sort(x); // This is the address of array x[n] .
for(i=0; i<n; i++)
printf("\n %d",x[i]);
return 0;
}
void bubble_sort(int x[n])
{
int i,j;
int tmp1;
for(i=0; i<n; i++)
{
for(j=0; j<n-1; j++)
{
if(x[j]>x[j+1])
{
tmp1=x[j+1];
x[j+1]=x[j];
x[j]=tmp1;
}
}
}
return;
}
Particularly in code line
Code:
bubble_sort(x); // This is the address of array x[n] .
The x is the address of the first item of x[n] and generally is the address of x . This is call by reference??? Or call by value??? And if is call by reference how it works? Because I dont give a pointer into the function arguments only the array x[n].
Thank you very much in advance .