【c基础】c语言 变量 数组元素 数组名做函数参数传递

来源:互联网 发布:zblogasp转php 编辑:程序博客网 时间:2024/06/07 20:36

参数传递分为值传递和引用传递。

值传递,不改变原来值,开辟新内存(在堆中)

引用传递,改变原来值,传递指针

一、变量传递

(值传递)

xxxxxx

 int test(int a){

xxxxxxx

}

xxxxxxx

int a1;

test( a1 );

xxxxxxxx

二、数组元素传递

与变量传递相同

(值传递)

xxxxxx

 int test(int a){

xxxxxxx

}

xxxxxxx

int a1[2] = {2,3};

test( a1[0] );

xxxxxxxx

三、数组名传递

(引用传递)

xxxxxx

 int test(int a [ ]){

xxxxxxx

}

xxxxxxx

int a1[ 2 ] = { 2,3};

test( a1 );

xxxxxxxx


阅读全文
0 0