陣列 指標 2
user_6817964
c_cpp
3 years ago
436 B
9
Indexable
#include <stdio.h>
int main()
{
int a[5] = { 1, 2, 3, 4, 5 };
int *ptr = a;
for (int i = 0; i < 2; i++) {
ptr[i] += 3;
}
for (int i = 0; i < 5; i++)
printf("a[%d] = %d\n", i, a[i]);
printf("\n");
ptr = &a[2];
for (int i = 0; i < 2; i++) {
ptr[i] += 3;
}
for (int i = 0; i < 5; i++)
printf("a[%d] = %d\n", i, a[i]);
printf("\n");
}Editor is loading...