using only pointers instead of array indexing
This commit is contained in:
parent
22e3ed5406
commit
1b7572c786
6
ex15.c
6
ex15.c
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user