????C ?? C++ ????????????????? ????? C ?????? C++ ??????? ?????????????? C++ ??????????? ???????????C??????????????? ??????????????????校? C ?? C++ ??????????????????????????? ???????? C99 ????????? C++ ????//???? C++11 ?????? C99 ?? long long ????? ????
????C ?? C++ ??????????????????????妫�
????1??C++ ???? C ?????????
????2??C ???? C++ ?????????
????3??C ?? C++ ?????? ????/??????????????
????????????? ??????? OOP ????? template ????? ??????? C99 ??????胁???? ?????? C++11 ??????? ??? C99 ???????????????? C++ ??? ???????? ????????? ???????????????????????
???????????????????? C/C++?? ????????????????????
????const???畏?
????C ?? C++ ??????????????? ??????????????constant expression???? ???????????????????? ?????????????? ??些??????????贸????????? ????????????? case ????????? ????
????????? const ????????????????????????? ???? C ?? C++ ?胁???????? ??????????未???
????void foo() {
????const int N = 100;
????int arr[N];
????}
?????? C++ ?校? ??未?????????? ??? N ??????????? 100 ?????谩? (?? C++11 ?校? ?????????? constexpr)?? ???? C89 ?校? ??未?????????? ???????????????const?? ??????????????????
?????????????????? ???????未??? ??????????? ????????? C99?????????????(variable length array?? ??????写?VLA)?? arr ????????????VLA?? ?????????未????? C99 ?斜??????? ?? arr ????????????????????????????椋� ??? N ????????????????
????void *???
????void *????? C ???????????????? C++ ????????????? ???????懈??????????? void *??????????
????????????? void * ???????????????????????????? ?????? C ????????????????????????(implicit conversion)?? ???? C++ ?斜???????????????????explicit conversion????
??????????????
????void *ptr;
????int *a = ptr;
????int *b = (int *)ptr;
???????a???????? C ????????????? ???? C++ ????????? ??? b ???????? C/C++ ?卸????????
????????? C++ ?? C ?????????????????????
????????? malloc???????????????????? ??????
????int *x = malloc(sizeof(*x));
????int *y = (int *)malloc(sizeof(*y));
????????????????
????auto ?????
????C++11 ????? auto ????????????????? ?????? STL ???????????? ???? auto ??? ???????? ????? ??????? ??????未???
????void foo() {
????auto a = 42;
????}
?????? C89 ???????????????? ????? C ???????? auto ???
????????? auto ??????? C ???????????? ?????????伪????? ??????????????娲� (automatic storage)?? ?????娲�???? ??????? ????????? ????娲�?????????? static ????????危? ??????????????????娲�??? ???? auto ????????????????? ??????????谢??????????????? ?? C++11 ?? ?? auto ???????????渭????? ???????????????鈥�???
?????????????????? C ?????校? ???? a = 42;?? ???? C89 ?校? ???????????? int ????? ?????? int a = 42;?? ????? C99 ?校? ?????? int ????????????????
?????些????????
?????????????????????
????printf("%zu "?? sizeof('a'));
?????????渭???? C ?? C++ ?????????? C++ ?????? 1?? ?? C ??????????????泄?? ??????? 4?? sizeof(char) ????????????????????渭?? ??????澹� ???? 1?? ?????????????????????? C++ ?????????????? ?? 'a'?? ?????? char?? ?? C ????????????? int??
????????????????? bool?????? C ?????????????????????????? ??? C ????????? #define 1 TRUE ??????????????????? ?????????? C99 ??????????????????? ??????????? ???????????????? _Bool?? ???????? stdbool.h ?校? ??????? bool ??? true?? false ??????????谩? ??????? ?????????????? C ????
????#include <stdio.h>
????#include <stdbool.h>
????int main() {
????printf("%zu  %zu "?? sizeof(bool)?? sizeof(true));
????return 0;
????}
?????????????????小????????? ????????? ??????????????????? true ?? false ?????????纬??? 1 ?? 0?? ?????? C++ ?????????? bool ?????????
????C ?? C++ ?????????些???? ???? const ???????????梅?围?? inline ????????宸段�???? ???????????奴??? ?????????? ??????????????????????????????