遥远的青苹果

代码人生

 

C++中指针乱了!如何解决

   1: // TestArrayPtr.cpp : Defines the entry point for the console application.
   2: //
   3:  
   4: #include "stdafx.h"
   5: #include <stdio.h>
   6: #include <iostream>
   7: using namespace std;
   8:  
   9: int _tmain(int argc, _TCHAR* argv[])
  10: {
  11:  
  12:  
  13: int* p_Jtobus = new int[6];
  14:  
  15:   for (    int i=0;i<6;i++)
  16:   {
  17:  
  18:       p_Jtobus[i]=i;
  19:     
  20:   }
  21:    cout<<"小段程序一"<<endl; 
  22:    for (    int i=0;i<6;i++)
  23:   {
  24:       int s=  * p_Jtobus;
  25:     p_Jtobus++;
  26:  
  27:         cout<<"out putA"<<i<<"输出的值是"<<s<<endl; //iostream
  28:  
  29:   }
  30:    cout<<"小段程序二"<<endl; 
  31:   for (    int i=0;i<6;i++)
  32:   {
  33:       int s=  * p_Jtobus;
  34:       p_Jtobus++;
  35:  
  36:       cout<<"out putB"<<i<<"输出的值是"<<s<<endl; //iostream
  37:  
  38:   }
  39:  
  40:     char filename[30];
  41:     scanf("%s", filename);
  42:  
  43:     return 0;
  44: }

指针乱啦
第一次 和第二次

如何让他恢复到以前

各位看官如何解决呢!

期待你的静态答案!

第二个for之前
没有把p_Jtobus重置为原来的值

posted on 2012-08-04 10:07  遥远的青苹果-李院长  阅读(475)  评论(4编辑  收藏  举报

导航