1. 程式人生 > 其它 >指標與陣列的練習

指標與陣列的練習

技術標籤:C語言

*int find_middle(int a[],int n);
當傳遞長度為n的陣列a時,函式將返回指向陣列的中間元素的指標。(如果n是偶數,選擇較大下標的中間元素。例如,如果n=4,中間元素是a[2],不是a[1]。)

#include <stdio.h>
#include <stdlib.h>
int *fun(int x[], int n)
{
	int *w;
	w = &x[n/2];
	return w;
}
int main()
{
	int a[]={1,2,3,4,5,6,7,8};
	int b[]={4,5,6,7,8,9,10,11,12,13};
	int *p,*q;
	p = fun(a,8);
	q = fun(b,10);
	printf("a陣列的中間元素為 %d\n",*p);
	printf("b陣列的中間元素為 %d\n",*q);
	system("pause");
	return 0;
 } 

在這裡插入圖片描述