#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/**
* sizeof(city_array) = 8, sizeof(char *) = 8
* count = sizeof(city_array) / sizeof(char *) = 1
*/
void print_city_array(int num, char **city_array){
printf("sizeof(city_array) = %d, sizeof(char *) = %d\n", sizeof(city_array), sizeof(char *));
printf("count = sizeof(city_array) / sizeof(char *) = %d\n", sizeof(city_array)/sizeof(char *));
int i;
for(i = 0; i < num; i++){
puts(city_array[i]);
}
}
/**
* ==:sizeof(array) = 8, sizeof(int *) = 8, sizeof(array)/sizeof(int) = 2
*/
int get_total(int sum, int *array){
printf("==:sizeof(array) = %d, sizeof(int *) = %d, sizeof(array)/sizeof(int) = %d\n",
sizeof(array), sizeof(int *), sizeof(array)/sizeof(int) );
int i, total = 0;
for(i = 0; i < sum; i++)
total += array[i];
return total;
}
int main(int argc, char *argv[]) {
char *city_array[] = {
"beijing",
"shanghai",
"wuhan",
"xian"
};
puts("==========main starting========");
printf("sizeof(city_array) = %d, sizeof(char *) = %d\n", sizeof(city_array), sizeof(char *));
printf("count = sizeof(city_array) / sizeof(char *) = %d\n", sizeof(city_array)/sizeof(char *));
int i;
for(i = 0; i < sizeof(city_array)/sizeof(char *); i++){
puts(city_array[i]);
}
puts("==========main ending========");
print_city_array(4, city_array);
int array[] = {1, 9, 2, 8, 3, 7, 4, 6, 5};
int total = get_total(9, array);
printf("total = %d\n", total);
return 0;
}