C语言数组作为传入参数
上例子
常见的三种数组作为传入参数
#include<stdio.h>float average1(float a[5]) {int i;float sum=0;for(i=0;i<5;i++){sum+=a[i];}printf("1:%d %f ",sizeof(a),sum); }float average2(float a[]) {int i;float sum=0;for(i=0;i<5;i++){sum+=a[i];}printf("2:%d %f ",sizeof(a),sum); }float average3(float* a) {int i;float sum=0;for(i=0;i<5;i++){sum+=a[i];}printf("3:%d %f ",sizeof(a),sum); }int main(void) {float s[5] ={1.0,2.0,3.0,4.0,5.0};average1(s);average2(s);average3(s);return 0; } /* 1:4 15.000000 2:4 15.000000 3:4 15.000000sizeof(a)都是4;传入参数都视为指针 */