1. 数组和指针作为函数的参数的注意点:将数组作为参数的时候,会被转化成指针,例子如下:
#include <iostream>
using namespace std;
char fo[] = "foliage";
void my_arr_func(char foliage[10])
{
cout << "address of array param is : " << &foliage << endl;
}
void my_pointer_func(char* foliage)
{
cout << "address of pointer param is : " << &foliage << endl;
}
int main()
{
cout << "address of array param is : " << &fo << endl;
my_arr_func(fo);
my_pointer_func(fo);
system("PAUSE");
return 0;
}
2.区别下面代码:
(来自C专家编程)
func(int arr[])
{
arr[1] = 3;
*arr = 3;
arr = arr2;
}
----------------------
int array[100],array2[100];
main()
{
array[1] = 3;
*arr = 3;
array = array2; /*failed*/
}