C的指针,真的很经典

工作以后,一直使用C++,也做过Objective C,各种类的方法封装得很好,使用很简单,今天偶尔翻看一下 严蔚敏 的 《数据结构》,第一个程序demo就看了半天,一是由于demo的变量命名问题,全是i,m,n,p什么的;二就是对指针的使用生疏了。现在把改写的demo记录一下。。。

#include <stdio.h>
#include <stdlib.h>
   3:  
int nCount) {
int *pHead = pArray;
int *pTail = pArray + nCount - 1;
int iTemp = 0;
while(pHead < pTail) {
   9:         iTemp = *pTail;
  10:         *pTail = *pHead;
  11:         *pHead = iTemp;
  12:         pHead++;
  13:         pTail--;
  14:     }
  15:     pHead = NULL;
  16:     pTail = NULL;
  17: } 
  18:  
char *argv[]) {
int nCount = 0;
);
, &nCount);
int) * nCount);
int *pCounter = pArray;
);
int i = 0;
for(; i<nCount; i++) {
, pCounter++);
  29:     }
);
  31:     pCounter = pArray;
for(i=0; i<nCount; i++) {
, *(pCounter++));
  34:     }
  35:     Invert(pArray, nCount);
);
for(i=0; i<nCount; i++) {
, *(pArray++));
  39:     }
  40:     pCounter = NULL;
  41:     free(pArray);
  42:     pArray = NULL;
return 0;
  44: }