using only pointers instead of array indexing

This commit is contained in:
Dan Buch 2011-09-19 19:06:10 -04:00
parent 22e3ed5406
commit 1b7572c786

6
ex15.c
View File

@ -15,7 +15,7 @@ int main(int argc, char *argv[])
// first way using indexing
for(i = 0; i < count; i++) {
printf("%s has %d years alive.\n",
names[i], ages[i]);
*(names + i), *(ages + i));
}
printf("---\n");
@ -27,7 +27,7 @@ int main(int argc, char *argv[])
// second way using pointers
for(i = 0; i < count; i++) {
printf("%s is %d years old.\n",
*(cur_name+i), *(cur_age+i));
*(cur_name + i), *(cur_age + i));
}
printf("---\n");
@ -35,7 +35,7 @@ int main(int argc, char *argv[])
// third way, pointers are just arrays
for(i = 0; i < count; i++) {
printf("%s is %d years old again.\n",
cur_name[i], cur_age[i]);
*(cur_name + i), *(cur_age + i));
}
printf("---\n");