sizeof(city_array) = 8, sizeof(char *) = 8
#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 ", sizeof(city_array), sizeof(char *)); printf("count = sizeof(city_array) / sizeof(char *) = %d ", 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 ", 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 ", sizeof(city_array), sizeof(char *)); printf("count = sizeof(city_array) / sizeof(char *) = %d ", 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 ", total); return 0; }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: php读mysql中文乱码问题解决方法
- 下一篇: 值得推荐的C/C++开源框架和库