Sample Questions Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions  

Technical Sample Questions : C |  C++ |  Oracle |  Java | Unix |  Operating Systems |  Data Structure

Sample Technical Questions

C++ and OOPS Sample Question

  1. What is an action class?

    Answer:

    The simplest and most obvious way to specify an action in C++ is to write a function. However, if the action has to be delayed, has to be transmitted 'elsewhere' before being performed, requires its own data, has to be combined with other actions, etc then it often becomes attractive to provide the action in the form of a class that can execute the desired action and provide other services as well. Manipulators used with iostreams is an obvious example.

    Explanation:

    A common form of action class is a simple class containing just one virtual function.
    class Action
           {
                   public:
                        virtual int do_it( int )=0;
                        virtual ~Action( );
             }
    Given this, we can write code say a member that can store actions for later execution without using pointers to functions, without knowing anything about the objects involved, and without even knowing the name of the operation it invokes. For example: class write_file : public Action
    {
                  File& f;
                  public:
                      int do_it(int)
                     {
                           return fwrite( ).suceed( );
                     }
          };
         class error_message: public Action
         {
                    response_box db(message.cstr( ),"Continue","Cancel","Retry");
                    switch (db.getresponse( ))
                    {
                            case 0: return 0;
                            case 1: abort();
                            case 2: current_operation.redo( );return 1;
                     }
          }; 

    A user of the Action class will be completely isolated from any knowledge of derived classes such as write_file and error_message.
  2. When can you tell that a memory leak will occur?

    Answer:

    A memory leak occurs when a program loses the ability to free a block of dynamically allocated memory.
  3. What is a parameterized type?

    Answer:

    A template is a parameterized construct or type containing generic code that can use or manipulate any type. It is called 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.
  4. Differentiate between a deep copy and a shallow copy?

    Answer:

    Deep copy involves using the contents of one object to create another instance of the same class. In a deep copy, the two objects may contain ht same information but the target object will have its own buffers and resources. the destruction of either object will not affect the remaining object. The overloaded assignment operator would create a deep copy of objects. Shallow copy involves copying the contents of one object into another instance of the same class thus creating a mirror image. Owing to straight copying of references and pointers, the two objects will share the same externally contained contents of the other object to be unpredictable.

    Explanation:

    Using a copy constructor we simply copy the data values member by member. This method of copying is called shallow copy. If the object is a simple class, comprised of built in types and no pointers this would be acceptable. This function would use the values and the objects and its behavior would not be altered with a shallow copy, only the addresses of pointers that are members are copied and not the value the address is pointing to. The data values of the object would then be inadvertently altered by the function. When the function goes out of scope, the copy of the object with all its data is popped off the stack.
    If the object has any pointers a deep copy needs to be executed. With the deep copy of an object, memory is allocated for the object in free store and the elements pointed to are copied. A deep copy is used for objects that are returned from a function.
  5. What is an opaque pointer?

    Answer:

    A pointer is said to be opaque if the definition of the type to which it points to is not included in the current translation unit. A translation unit is the result of merging an implementation file with all its headers and header files.

« Previous || Next »

C++ Sample Question number : 1-3 | 4-7 | 8-10 | 11-13 | 14-21 | 22-28 | 29-35 | 36-42 | 43-49 | 50-54 | 55-58 | 59-66 | 67-73 | 74-80
Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions

Other Sample Questions
Sample Interview Questions
Sample Teacher Interview Questions
Sample Citizenship Questions
Accuplacer Sample Questions
Science Bowl sample Questions
Driving Test Sample Questions
Sample Survey Questions Sample Essay Questions
Sample Behavioral Interview Questions

Copyright © 2004-2013, Best BSQ. All Rights Reserved.