嗨朋友们,我正在尝试将元素分配arr2[]
给指针p_arr
,然后尝试从p_arr
...打印
我认为有些事情搞砸了,没有得到预期的价值......
#include <stdio.h>
#include <stdlib.h>
#define MAX_ONE 9
#define MAX_TWO 9
int arr1[] = {10,20,30,40,50,67,23,47,79};
int arr2[] = {5,15,25,35,45,34,45,67,89};
int *main_arr[] = {arr1,arr2};
int main()
{
int i;
int *p_arr2;
p_arr2 = (int *)malloc(sizeof(int)*2);
for(i=0;i<MAX_ONE;i++)
{
*p_arr2++ = arr2[i];
arr2[i] = arr1[i];
}
for(i=0;i<MAX_TWO;i++)
{
printf("%d\n",*(p_arr2));
p_arr2++;
//printf("%d\t",arr2[i]);
}
system("PAUSE");
return 0;
}