What are the major differences between C and C++?
The main difference between C & C++ is the OOPS technology, C++ is an object oriented programing language.
# What are the differences between new and malloc?
The main difference between malloc() and new is that new calls a class constructor after allocating the memory. The malloc() function allocates the requested number of bytes and returns a pointer to them. The main difference between delete and free() is that delete calls the class destructor method before returning the memory to the system.
# What is the difference between delete and delete[]?
The delete [] form should be used when freeing up arrays, The delete form should be used for single instances.
# What's the difference between "const Fred* p", "Fred* const p" and "const Fred* const p"?
You have to read pointer declarations right-to-left.
const Fred* p means "p points to a Fred that is const" — that is, the Fred object can't be changed via p.
Fred* const p means "p is a const pointer to a Fred" — that is, you can change the Fred object via p, but you can't change the pointer p itself.
const Fred* const p means "p is a const pointer to a const Fred" — that is, you can't change the pointer p itself, nor can you change the Fred object via p.
What are the differences between a struct in C and in C++?
What are the advantages/disadvantages of using #define?
What are the advantages/disadvantages of using inline and const?
What is the difference between a pointer and a reference?
When would you use a pointer? A reference?
What does it mean to take the address of a reference?
What does it mean to declare a function or variable as static?
What is the order of initalization for data?
What is name mangling/name decoration?
What kind of problems does name mangling cause?
How do you work around them?
What is a class?
What is the difference between public, private, and protected access?
For class CFoo { }; what default methods will the compiler generate for you>?
How can you force the compiler to not generate them?
What is the purpose of a constructor? Destructor?
What is a constructor initializer list?
When must you use a constructor initializer list?
What is a:
Constructor?
Destructor?
Default constructor?
Copy constructor?
Conversion constructor?
What does it mean to declare a...
member function as virtual?
member function as static?
member function as static?
member variable as static?
destructor as static?
Can you explain the term "resource acquisition is initialization?"
What is a "pure virtual" member function?
What is the difference between public, private, and protected inheritance?
What is virtual inheritance?
# What is placement new?
Operator new allocates memory from the heap. Standard C++ also supports placement new operator, which constructs an object on a pre-allocated buffer. This is useful when building a memory pool, a garbage collector or simply when performance and exception safety are paramount (there's no danger of allocation failure since the memory has already been allocated, and constructing an object on a pre-allocated buffer takes less time):
void placement() {
char *buf = new char[1000]; //pre-allocated buffer
string *p = new (buf) string("hi"); //placement new
string *q = new string("hi"); //ordinary heap allocation
cout< c_str()< c_str();
What is the difference between operator new and the new operator?
What is exception handling?
Explain what happens when an exception is thrown in C++.
What happens if an exception is not caught?
What happens if an exception is throws from an object's constructor?
What happens if an exception is throws from an object's destructor?
What are the costs and benefits of using exceptions?
When would you choose to return an error code rather than throw an exception?
What is a template?
What is partial specialization or template specialization?
How can you force instantiation of a template?
What is an iterator?
What is an algorithm (in terms of the STL/C++ standard library)?
What is std::auto_ptr?
What is wrong with this statement? std::auto_ptr ptr(new char[10]);
It is possible to build a C++ compiler on top of a C compiler. How would you do this? (I was asking him how cfront was put together.)
# How does the Assignment operator work?
The assignment operator has five steps:
Test for assignment to self.
Free up existing memory. (delete)
Allocate new memory.
Copy.
Return *this;
Every class that has external resources (dynamic memory) should implement the destructor, assignment operator, and copy constructor.
# Where is the copy constructor used:
Initializing variables.
Passing function argument values.
Returning values from a function.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment