有两种情形;
一种是数组元素作为函数实参;一种是数组名作为函数参数;
新建一个VC6单文档工程;
void printshz(int , CDC* , int , int );
double getav(int a[5]);
......
void CShzcshView::OnDraw(CDC* pDC)
{CShzcshDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereint a[] = {11, 22, 33, 44, 55};for(int i=0; i<5; i++){printshz(a[i],pDC,30+i*50, 30);}double d1 = getav(a);CString str1;str1.Format("%lf", d1);pDC->TextOut(60, 60, str1);
}
......
void printshz(int a, CDC* pDC, int x, int y)
{CString str1;str1.Format("%d", a);pDC->TextOut(x, y, str1);
}double getav(int a[5]){int i;double av,s=a[0];for(i=1;i<5;i++)s=s+a[i];av=s/5;return av;
}
函数声明放到视类cpp文件的头部;
先是每次把数组的值传给printshz函数打印数组;
getav(a); 数组名作为函数参数;