1、输出数组元素地址
#include<stdio.h> #include<string.h> int main() { char arr[] = "abcdef"; int i = 0; for (i = 0; i < strlen(arr); i++) { printf("&arr[%d]=%p\n", i, &arr[i]); } }
2、定义二维数组的时候,列数是不可缺省的。
int arr[][4]={1,2,3,4,5,6,7,8};
二维数组的输出
#include<stdio.h> #include<string.h> int main() { int arr[3][4] = {1,2,3,4,5,6,7,8}; int i = 0; for (i = 0; i < 3; i++) { int j = 0; for (j = 0; j < 4; j++) { printf("%d ", arr[i][j]); } printf("\n"); } }
3、冒泡排序
#include<stdio.h> void bubble_sort(int arr[],int sz0) { int x = 0; for (x = 0; x < sz0 - 1; x++) { int y = 0; for (y = 0; y < sz0 - 1 - x; y++) { if (arr[y] > arr[y + 1]) { int tmp = arr[y]; arr[y] = arr[y+1]; arr[y + 1] = tmp; } } } } int main() { int arr1[10] = { 100,8,102,33,45,77,32,45,21,12 }; int sz1 = sizeof(arr1) / sizeof(arr1[0]); bubble_sort(arr1, sz1); int k = 0; for (k = 0; k < sz1; k++) { printf("%d ", arr1[k]); } return 0; }
注意观察bubble_sort()的形参。
标签:arr,int,学习,++,arr1,printf,include From: https://www.cnblogs.com/AvalonForLovers/p/17648794.html