#includeint main (int arg,char *argv[]) { int distance = 100; float power = 2.345f; double super_power = 56789.4532; char initial = 'A'; char first_name[] = "zed"; char last_name[] = "shaw"; printf("you are %d miles away.n",distance); printf("you have %f levels of power.n",power); printf("you have %f awesome super power.n",super_power); printf("I have an initial %c.n",initial); printf("I have a first name %s.n",first_name); printf("I have a last name %s.n",last_name); int bug = 100; double bug_rate = 1.2; printf("YOu have %d,%f.n",bug,bug_rate); long universe_of_detects = 1L * 1024L * 1024L * 1024L; printf("universe_of_detects = %ld",universe_of_detects); return 0; }
重点问题(1)int和long最大多少
可以发现原数据中的定义long变为int还是满足数据长度
long再乘以10倍发现已经报错
warning: integer overflow in expression of type ‘long int’ results in ‘-2147483648’ [-Woverflow]
long universe_of_detects = 1L * 10240L * 1024L * 1024L;
(2)%c和%s使用问题
字符用字符串打印会报错
字符串用字符打印程序不报错,但是打印内容报错。
char initial = ‘A’; //这个是定义一个字符,注意‘’单引号。
char initial =“A”; //这个是定义一个字符串,注意”“双引号。
字符串就是”字符数组“,利用数组访问的形式可以访问字符串里的字符。



