奇数的逆序写法----偶数这个有bug,这里主要是熟练指针的用法,针对偶数,等后续学习中再做补充
#include <stdio.h>
#include <stdlib.h>
#define N 5
int main()
{
int i,temp;
int nums[N]={22,77,44,55,88};
int *ptr_num_start = nums;
int *ptr_num_end = nums+N-1;
while(ptr_num_start != ptr_num_end){
temp = *ptr_num_start;
*ptr_num_start = *ptr_num_end;
*ptr_num_end = temp;
ptr_num_start++;
ptr_num_end--;
}
for(i=0;i<N;i++){
printf("%d\t",*(nums+i));
}
return 0;
}
指针访问二维数组的三种方法
#include <stdio.h>
#include <stdlib.h>
#define N 5
int main()
{
int i,j;
int nums[5][3]={
{33,44,55},
{23,54,75},
{11,26,90},
{65,68,89},
{24,49,81}
};
int (*ptr_nums)[3]=nums;
for(i=0;i<5;i++){
for(j=0;j<3;j++){
// printf("%d\t",nums[i][j]);
//printf("%d\t",*(nums[i]+j));
// printf("%d\t",*(*(nums+i)+j));
printf("%d\t",*(*(ptr_nums+i)+j));
}
printf("\n");
}
return 0;
}