Posted on 2011-05-27 21:30
Kevin_Zhang 閱讀(300)
評論(0) 編輯 收藏 引用 所屬分類:
C/C++
用指針操作數(shù)組。要求先輸出數(shù)組,然后將數(shù)組倒置,再輸出倒置的數(shù)組。
源代碼:
// test3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;


int main(int argc, char* argv[])


{
int *ptr1,*ptr2,t;

int a[]=
{1,2,3,4,5,6,7,8,9,10};
ptr1=a;
ptr2=&a[9];
for(int i=0;i<10;i++)
cout<<*(ptr1+i)<<" ";
cout<<endl;
while(ptr2>ptr1)

{
t=*ptr1;
*ptr1=*ptr2;
*ptr2=t;
ptr1++;
ptr2--;
}
ptr1=&a[0];
for(int j=0;j<10;j++)
cout<<ptr1[j]<<" ";
cout<<endl;
return 0;
}

