Saturday, February 10, 2007

Where C/C++ differ?

  1. Implicit assignment from void*: in C, is ok; in C++, not safe, cannot compile
  2. Freeing arrays: in C, use malloc and free for single elements and arrays; in C++, you much match calls to new/delete, new[]/delete[]
  3. Functions must be decleared before use
  4. struct: in C, you have to include keyword struct in order to declear a struct_instance; in C++, you don't have to do so.
  5. C++ has a much larger library: sometimes you want to compile a math heavy computation program, you could use gcc foo.c -lm/g++ foo.cc
  6. C didn't provide a boolean type, you could use enum to define.
  7. C++ may automatically add return 0 at the end of the main(); however in C you have to do it yourself.
  8. C requires define all the variables before a block of codes; C++ not necessary.

No comments: