文章目錄
- C++ & C
- Standard C/C++ Comparisons
- Cruel comparisons
C++ & C
- Can you declare a C struct that looks like a C++ class and somehow call member functions?
- What is the difference between a parameter and an argument?
Standard C/C++ Comparisons
- How can you make C code resemble C++ code? (i.e. write object oriented code with C)
- State some differences between a C struct and a C++ struct.
- Write a snippet of code that will compile in C but not in C++.
- What is the difference between malloc and operator new?
Answer: The difference is really the return value and arguments each take. To begin with malloc is a function whereas new is an C++ operator. malloc returns a void pointer and it is the responsibility of the user to typecast to the appropriate data type whereas new returns object of type being allocated. malloc takes in number of bytes to be allocated as the parameter which is an integer (or size_t) whereas new takes the type of the datatype(can be a class as well). Bonus: It is generally not a good idea to mix C and C++ i.e. use malloc and use delete or use new and use free Item 3 : Effective C++
Cruel comparisons
- Are C programmers better than C++ programmers?
Answer: This is really not an apple to apple comparision. Let us drop this question right here
- Why are open source operating systems written in C instead of C++?
Answer:Performance is a factor rather than re usability.
- What makes C more suitable for writing threaded apps than C++?
Answer: Performance again