Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình C

Khác biệt không tương thích giữa C và C++

Code C hợp lệ nhưng lỗi C++:

  1. K&R function definition: void f(x,y)int x;int y;{} → C++ lỗi
  2. Implicit int: const x=10; → C++ lỗi "does not name a type"
  3. Tên trùng lặp global: int x; int x; → C++ lỗi "redefinition"
  4. void* gán ngầm: int* p = malloc(...); → C++ cần cast
  5. Hàm không tham số: void f(){} f(1,2); → C++ lỗi "too many arguments"