#include <stdio.h> void init(int *arr, int size) { int i = 0; for (i = 0; i < size; i++) { arr[i] = i; } } void print(int *arr, int size) { int i = 0; for (i = 0; i < size; i++) { printf("%d ", arr[i]); } printf("\n"); } void empty(int *arr, int size) { int i = 0; for (i = 0; i < size; i++) { arr[i] = 0; } } static void swap(int *p1, int *p2) { int tmp = *p1; *p1 = *p2; *p2 = tmp; } void reverse(int *arr, int len) { int left = 0; int right = len - 1; while (left < right) { swap(&arr[left], &arr[right]); left++; right--; } } int main() { int arr[10]; int len = sizeof(arr) / sizeof(arr[0]); init(arr,len); print(arr, len); reverse(arr, len); print(arr, len); empty(arr, len); print(arr, len); system("pause"); return 0; }
本文出自 “Vs吕小布” 博客,请务必保留此出处http://survive.blog.51cto.com/10728490/1705307
原文地址:http://survive.blog.51cto.com/10728490/1705307