?? 函數傳遞數組的方法.cpp
字號:
#include <iostream.h>
void show_array1(int*,int);
void show_array2(int a[],int);
void sort(int*,int);
main()
{
//聲明數組并初始化
int a[]={2,4,6,1,3,5};
int b[3][3]={{2,4,6},{1,3,5},{0,1,2}};
//顯示數組的值
cout<<"show_array1(int*,int):"<<endl;
show_array1(a,6);
show_array1(&b[0][0],3*3);
//用sort1排序并顯示
cout<<"sort(int*,int) and show_array1(int*,int):"<<endl;
sort(a,6);
show_array1(a,6);
sort(&b[0][0],3*3);
show_array1(&b[0][0],9);
//顯示數組的值
cout<<"show_array2(int a[],int):"<<endl;
show_array2(a,6);
show_array2(&b[0][0],3*3);
}
//顯示數組,用指針當參數
void show_array1(int *p,int size)
{
for (int i=0;i<size;i++)
cout<<*(p+i)<<" ";
cout<<endl;
}
//顯示數組,用數組當參數
void show_array2(int a[],int size)
{
for (int i=0;i<size;i++)
cout<<*(p+i)<<" ";
cout<<endl;
}
//顯示數組,用數組當參數
void show_array2(int a[],int size)
{
for (int i=0;i<size;i++)
cout<<a[i]<<" ";
cout<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -