Home > Back-end > Pointer to learn, you can help me to look at it
Pointer to learn, you can help me to look at it
Time:09-23
Write function fun, defined as: void fun (int * a, int n)
Function is: will a referred to in the first half of the array elements and parameters are in the second part element value exchange, the number of data in the array in the parameter n, if n is odd, is in the middle of the elements, for example, if a referred to an array of data in the order: 1,4,3,2,5,6,8,7,9, after changing as: 6,8,7,9,5,1,4,3,2,
The main function is defined in 10 the length of the array, the input of n (n<=10) represents the number of array elements of concrete, calls the fun function and output results,
#include
Void fun (int * a, int n) { Int I, p [10]. A=& amp; P; {if (n % 2==0) for (i=0; i [I]=p * (a + I + n/2); } For (I=n/2; i [I]=p * (a + I - n/2); }
} return p;
}
Int main () { Int n, I, p [10]; Int * a=& amp; P; Printf (" input tuple element number: "); Scanf_s (" % d ", & amp; N); Printf (" input tuple element: "); for (i=0; i Scanf_s (" % d ", & amp; P [I]);
Fun (a, n); for (i=0; i Printf (" % d ", p [I]); return 0;
}
CodePudding user response:
You read the p [10] defined as a global variable, the function defined in the p [10] deleted, so can't return
CodePudding user response:
Don't return to a local variable, or use a global variable, or made into a pointer, the incoming buffer address assignment within the function