指针参数是如何传递内存的?

指针参数是如何传递内存的?

如果函数的参数是一个指针,不要指望用该指针去申请动态内存。 

 

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6     
 7     int i,max,index,a[5];
 8 
 9     //从键盘上为数组赋值
10      for (i=0;i<=4;i++)
11      {
12        cout<<"a["<<i<<"]=";
13        cin>>a[i];
14      }
15 
16     // 利用循环遍历数组,找出最大值的元素及其下标
17     max=a[0];
18     for (i=0;i<=4;i++)
19     {
20             if (max<a[i])
21             {
22                 max=a[i];
23                 index=i;
24             }
25         }
26     cout<<"\nMax="<<max<<"  index="<<index;
27     return 0;
28 }

 

posted @ 2018-08-02 12:17  borter  阅读(126)  评论(0编辑  收藏  举报