1.int main(void)
{
int a[5] = { 10,20,30,40,50 };//数组间的元素地址相连的
int* p;
printf("%d\n", &a[0]);
printf("%d\n", &a[1]);
printf("%d\n", &a[2]);
printf("%d\n", &a[3]);
printf("%d\n", &a[4]);
printf("a代表的地址:%d\n", a);//数组首个元素的地址
printf("a+1代表的地址:%d\n", a+1);//偏移数组
printf("a+2代表的地址:%d\n", a+2);
printf("a+3代表的地址:%d\n", a+3);
printf("a+4代表的地址:%d\n", a+4);
printf("a[4]代表的地址:%d\n", &a[2]+2);
printf("*(a+2)的值:%d\n", *(a+2));//调用数组元素用*
}
2.
//数组的遍历与练习 /* public static void main(String[] args) { int []arr={1,2,3,4,5}; for (int i = 0; i <= 4; i++) { System.out.println(arr[i]); } System.out.println(arr.length);//数组的长度 for (int i = 0; i < arr.length; i++) {//arr.fori System.out.println(arr[i]); } }*/ //遍历数组并求和 /*public static void main(String[] args) { int sum=0; int []arr={1,2,3,4,5}; for (int i = 0; i < arr.length; i++) { sum=sum+arr[i]; } System.out.println(sum); }*/ /* public static void main(String[] args) { int []arr={1,2,3,4,5,6,7,8,9,10}; int num=0; for (int i = 0; i < arr.length; i++) { if(arr[i]%3==0){ System.out.println(arr[i]); num++; } } System.out.println(num); }*/ public static void main(String[] args) { int []arr={1,2,3,4,5,6,7,8,9,10}; for (int i = 0; i < arr.length; i++) { if(arr[i]%2==0){ arr[i]=arr[i]/2; } else { arr[i]=arr[i]*2; } } for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } }