Thursday, March 13, 2014

Test Your C++ Skills

Q : Explain in void pointer using C++?
A : In C++, void represents the absence of type, so void the pointers are pointers that point to a value that has no type. The void pointers can point to any data type.
We can declare void pointer as follows.
Void *p;

Q : What is the function overloading in C++?
A :  You can have the multiple functions with same name using function overloading facility of C++. You can use same name for multiple functions when all these functions are doing same thing.

Q : What is virtual function?
Answer - Virtual function is the member function of a class that can be overridden in its derived class. It is declared with virtual keyword. Virtual function call is resolved at run-time (dynamic binding) whereas the non-virtual member functions are resolved at compile time (static binding).

Q : What is  Null object in C++?
A : Null Object  is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member of function that is supposed to return an object with some specified properties but cannot find such an object.

Q : What is virtual function? where is it used?
A : Virtual function is a member of function that is declared by with in a base class and redefined by the derived class. to make a function virtual prefix the function name by the "virtual" keyword. It helps in polymorphism.

Q : what is a template
A template function defines a set of operations to performed on the various data types This data is passed to the function as an argument

Q : What do you mean by the inheritance?
A : The Inheritance is the process by which one can aquire the properties of another object

Q : Explain the scope resolution operator?
A: The scope resolution operator is a  permits of a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.

Q : What is  parameterized type?
A :  : A template is a parameterized construct or type containing the generic code that can use or manipulate any type. It is called the parameterized because an actual type is a parameter of the code body. Polymorphism may be achieved through parameterized types. This type of polymorphism is called parameteric polymorphism. Parameteric polymorphism is the mechanism by which the same code is used on different types passed as parameters.

Q  : Explain the scope resolution operator?
A :Resolution operator permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.

Q : Name of the some pure object oriented languages?
A : Some pure object oriented languages are
• Smalltalk,
• Java,
• Eiffel,
• Sather.

Q : Differentiate between a C++ struct and C++ class?
A : The default member and base-class access specifies are different. This is one of the commonly misunderstood aspects of C++. Believe it is or not, many programmers think that a C++ struct is just like a C struct, while a C++ class has inheritance, access specifies, member functions, overloaded operators, and so on. Actually, the C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base-class inheritance, and a class defaults to the private access specified and private base-class inheritance.

Q : Why do C++ compilers need the name mangling?
A : Name mangling is the rule of according to which is the C++ changes function's name into function signature before the passing that the function to a linker. This is how the linker differentiates between different functions with the same name.

Q : What is  protocol class?
A : An abstract class is a protocol class if:
1.Protocol  neither contains nor inherits from the classes that contain member data, non-virtual functions, or private (or protected) members of any kind.
2. It has a non-inline virtual destructor defined with an empty implementation,
3. All member functions other than the destructor including inherited functions, are declared pure the virtual functions and left undefined.

Q  : What is the difference between the message and method?
A: Method: Provides response to a message.It is an implementation of an operation..
Message: Objects communicate by sending the messages to each other.A message is sent to invoke a method.

Q  : What is an adaptor class ?
A  : A class that has no functionality of its own. It is the member functions hide the use of a third party software component or an object with the non-compatible interface or a non- object- oriented implementation.

Q : What’s the difference between char a[] = “string”; and char *p = “string”;?
A : In the first case six bytes are allocated to the variable in a  which is fixed, where as in the second case if *p is assigned to the some other value the allocate memory can change.

Q : What is  conversion constructor?
A : A conversion constructor is that accepts one argument of a different type.

Q : What’s  an explicit constructor?
A : A conversion constructor declared with the explicit keyword. The compiler does’nt use an explicit constructor to implement an implied conversion of types. It is the  purpose of  is reserved explicitly for construction.