treating pointer args as arrays

This commit is contained in:
Dan Buch 2011-09-19 23:06:33 -04:00
parent bf6752edd6
commit a584141d4d

8
ex15.c
View File

@ -1,6 +1,6 @@
#include <stdio.h> #include <stdio.h>
void print_with_array_indexing(int count, char *names[], int ages[]) void print_with_array_indexing(int count, char **names, int *ages)
{ {
int i = 0; int i = 0;
@ -13,7 +13,7 @@ void print_with_array_indexing(int count, char *names[], int ages[])
printf("---\n"); printf("---\n");
} }
void print_with_pointer_arithmetic(int count, char *names[], int ages[]) void print_with_pointer_arithmetic(int count, char **names, int *ages)
{ {
int i; int i;
// setup the pointers to the start of the arrays // setup the pointers to the start of the arrays
@ -29,7 +29,7 @@ void print_with_pointer_arithmetic(int count, char *names[], int ages[])
printf("---\n"); printf("---\n");
} }
void print_with_pointers_as_arrays(int count, char *names[], int ages[]) void print_with_pointers_as_arrays(int count, char **names, int *ages)
{ {
int i; int i;
int *cur_age = ages; int *cur_age = ages;
@ -44,7 +44,7 @@ void print_with_pointers_as_arrays(int count, char *names[], int ages[])
} }
void print_in_stupidly_complex_way(int count, char *names[], int ages[]) void print_in_stupidly_complex_way(int count, char **names, int *ages)
{ {
int *cur_age = ages; int *cur_age = ages;
char **cur_name = names; char **cur_name = names;