????5.
????int my_strlen(const char *x)
????{
????int res = 0;
????while(*x)
????{
????res++;
????x++;
????}
????return res;
????}
????Q: ?????????????÷??????????????β??????????????????д??????? bug ??
????A: ??? int ???????洢??????С???????????????? int ????????????κζ?????С???????? size_t??
????6.
????#include <stdio.h>
????#include <string.h>
????int main()
????{
????const char *str = "hello";
????size_t length = strlen(str);
????size_t i;
????for(i = length - 1; i >= 0; i--)
????{
????putchar(str[i]);
????}
????putchar('n');
????return 0;
????}
????Q: ????????????????????????
????A: size_t ???????????? ??? i ???????????? ??? i >= 0 ?????????????
????7.
????#include <stdio.h>
????void f(int *i?? long *l)
????{
????printf("1. v=%ldn"?? *l);
????/* (1) */
????*i = 11;
????/* (2) */
????printf("2. v=%ldn"?? *l);
????/* (3) */
????}
????int main()
????{
????long a = 10;
????f((int *) &a?? &a);
????printf("3. v=%ldn"?? a);
????return 0;
????}
???????????????????????????????????????С??????????????С??????????????????????
????1. v=10    2. v=11    3. v=11
????1. v=10    2. v=10    3. v=11
????Q??????ν???????????
????A?????????????δ??????????????Υ???????????????????strict aliasing??????? int ??? (2) ?б????????????????????????κε? long ????и?????????????????Щ????????????????????????????????????????????????????????е???й????б??????????? long (??(3)??)?????
????8.
????#include <stdio.h>
????int main()
????{
????int array[] = { 0?? 1?? 2 };
????printf("%d %d %dn"?? 10?? (5?? array[1?? 2])?? 10);
????}
????Q: ???????????????????????????δ???????????????????????
????A: ???? ?????????????????????????????????????????????????????????????????????????????????????????????? 10 2 10??
?????????????????е???????????? f(a()?? b())???????????????????????????????????a() ?? b() ???????????????
????9.
????unsigned int add(unsigned int a?? unsigned int b)
????{
????return a + b;
????}
????Q: ???? add(UINT_MAX?? 1) ??????????
????A????????????????????????ж?????????? 2^(CHAR_BIT * sizeof(unsigned int)) ????????? add ?????? 0 ??
????10.
????int add(int a?? int b)
????{
????return a + b;
????}
????Q?????? add(INT_MAX?? 1) ??????????
????A???з?????????????????δ??????????
????11.
????int neg(int a)
????{
????return -a;
????}
????Q???????????????δ?????????????????????????????????????????
????A??neg(INT_MIN)????? ECM ?????????????????????? ??? INT_MIN ????? INT_MAX ??????????????????£?-INT_MIN ??????з?????????????????????δ??????????
????12.
????int div(int a?? int b)
????{
????assert(b != 0);
????return a / b;
????}
????Q???????????????δ?????????????????????????????????????
????A????? ECM ??????????????? ??? div(INT_MIN?? -1) ??????????????????????????