Friday, February 5, 2010

c++ useful tips

1) pointer to null is a pointer where it points nowhere but pointer to void is a pointer where it points to something which is undefined.

2) Compile time error is an error when the code is unable to be compiled where as run time error is is an error when the prescribed input is not give like dived by zero.

3) cannot convert ‘int*’ to ‘char*’ in initialization but can convert int to char.

4)pointer to a virtual base class function cannot be converted into a derived class member.

5)A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system).

6)In computer security and programming, a buffer overflow, or buffer overrun, is an anomaly where a process stores data in a buffer outside the memory the programmer set aside for it. The extra data overwrites adjacent memory, which may contain other data, including program variables and program flow control data.

7)"this" is always a const pointer; it cannot be reassigned.

8)Constructors and destructors cannot be declared as const or volatile. They can, however, be invoked on const or volatile objects.

8) In C++, a structure is the same as a class except that its members are public by default.

9) should not use typedef in either constructor or destructor declaration

10) The differences between a static member function and non-static member functions are as follows.

* A static member function can access only static member data, static member functions and data and functions outside the class. A non-static member function can access all of the above including the static data member.
* A static member function can be called, even when a class is not instantiated, a non-static member function can be called only after instantiating the class as an object.
* A static member function cannot be declared virtual, whereas a non-static member functions can be declared as virtual
* A static member function cannot have access to the 'this' pointer of the class.

11) A function call is lvalue only if the result type is a reference.

12) The difference between a non-virtual c++ member function and a virtual member function is, the non-virtual member functions are resolved at compile time.

13)C++ provides three different types of polymorphism.

* Virtual functions
* Function name overloading
* Operator overloading

14) dynamic_cast can be used only with pointers and references to objects. Its purpose is to ensure that the result of the type conversion is a valid complete object of the requested class.base-to-derived conversions are not allowed with dynamic_cast unless the base class is polymorphic.

15) main() is never recursive though some compilers say it is so.

No comments:

Post a Comment