wingnut2626
December 26th, 2013, 02:31 AM
#include <stdio.h>
void iterateThroughArrays(char *arguments[], int numbers[]);
int main(int argc, char *argv[])
{
char *names[] = {"Ron", "Jen", "Jazlyn", "Reid"};
int ages[] = {30, 30, 3, 40};
printf("%ld is the size of actual ages", sizeof(ages));
getchar();
iterateThroughArrays(names, ages);
return 0;
}
void iterateThroughArrays(char *arguments[], int numbers[])
{
int i = 0;
printf("%ld is the size of numbers (ages) ", sizeof(numbers));
getchar();
printf("%ld is the size of an integer", sizeof(int));
getchar();
int total_ages = sizeof(numbers) / sizeof(int);
for(i = 0; i < total_ages; i++){
printf("%s is %d years old", arguments[i], numbers[i]);
getchar();
}
}
Thats my code. Now check out the output
16 is the size of actual ages
8 is the size of numbers (ages)
4 is the size of an integer
Ron is 30 years old
Jen is 30 years old
After ages[] gets passed into iterateThroughArrays, the number of items in "ages" gets cut in half. Why is that?
void iterateThroughArrays(char *arguments[], int numbers[]);
int main(int argc, char *argv[])
{
char *names[] = {"Ron", "Jen", "Jazlyn", "Reid"};
int ages[] = {30, 30, 3, 40};
printf("%ld is the size of actual ages", sizeof(ages));
getchar();
iterateThroughArrays(names, ages);
return 0;
}
void iterateThroughArrays(char *arguments[], int numbers[])
{
int i = 0;
printf("%ld is the size of numbers (ages) ", sizeof(numbers));
getchar();
printf("%ld is the size of an integer", sizeof(int));
getchar();
int total_ages = sizeof(numbers) / sizeof(int);
for(i = 0; i < total_ages; i++){
printf("%s is %d years old", arguments[i], numbers[i]);
getchar();
}
}
Thats my code. Now check out the output
16 is the size of actual ages
8 is the size of numbers (ages)
4 is the size of an integer
Ron is 30 years old
Jen is 30 years old
After ages[] gets passed into iterateThroughArrays, the number of items in "ages" gets cut in half. Why is that?