????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 ????????巶Χ???? ???????????ū??? ?????????? ??????????????????????????????