Thursday, December 14, 2017

Test your knowledge in C++

    1. What is a class? 
    A class in C++ is a user defined type or data structure declared with keyword class that has data and functions (also called methods) as its members whose access is governed by the three access specifiers private, protected or public (by default access to members of a class is private).

    2. What is an object? 
    Object (computer science) ... In the class-based object-oriented programming paradigm, "object" refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures.

    3. What is the difference between an object and a class? 
    Object is the physical as well as logical entity where as class is the only logical entity. Class: Class is a blue print which is containing only list of variables and method and no memory is allocated for them.

    4. What is the difference between class and structure? 
    A class has all members private by default. A struct is a class where members are public by default. Classes allow to perform cleanup (garbage collector) before object is deallocated because garbage collector works on heap memory. Objects are usually deallocated when instance is no longer referenced by other code.

    5. What is public, protected, private? 
    The access restriction to the class members is specified by the labeled public, private, and protected sections within the class body. The keywords public, private, and protected are called access specifiers. A class can have multiple public, protected, or private labeled sections.

    6. What are virtual functions? 
    A virtual function is a member function that you expect to be redefined in derived classes. When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class's version of the function.

    7. What is a scope resolution operator? 
    The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a namespace scope or global scope name is hidden by an explicit declaration of the same name in a block or class.

    8. What do you mean by inheritance?
    Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own. It permits code reusability

    9. What is abstraction? 
    Through the process of abstraction, a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency.

    10. What is polymorphism? 
    The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.

    11. What is encapsulation? 
    Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse.

    12. What do you mean by binding of data and functions? 
    Binding of data and functions in one single unit named class is know as encapsulation. Encapsulation provides data hiding facility. In programming languages encapsulation is implemented using classes. Basically binding means to associate data and functions with a particular unit i.e. class

    13. What is function overloading and operator overloading? 
    Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types. Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes.

    14. What is virtual class and friend class? 
    A virtual class is an inner class that can be overridden by derived classes of the outer class.friend class is used to share private data between 2 or more classes the function declared as freind are not called using any object it is called like normal .the arguments to
    such functions is normally object of a class.

    A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

    15. What do you mean by inline function? 
    The inline functions are a C++ enhancement feature to increase the execution time of a program. Functions can be instructed to compiler to make them inline so that compiler can replace those function definition wherever those are being called.

    16. What do you mean by public, private, protected and friendly? 
    Some languages define internal as an access specifier which means the data member or method is available to all the classes inside that particular assembly. Friend: A friend class or method can access all data of a class including private and protected data.

    17. When is an object created and what is its lifetime? 
    Object is created when constructor has to be invoked or when have to access the class.Its Lifetime is throughout the Execution of that Class.

    18. What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.
    “Multiple Inheritance” refers to the concept of one class extending (Or inherits) more than one base class. Multilevel inheritance refers to a mechanism in OO technology where one can inherit from a derived class, thereby making this derived class the base class for the new class.

    19. Difference between realloc() and free? 
    An existing block of memory which was allocated by malloc() subroutine, will be freed by free() subroutine. In case , an invalid pointer parameter is passed, unexpected results will occur. If the parameter is a null pointer, then no action will occur.
    - Where as the realloc() subroutine allows the developer to change the block size of the memory which was pointed to by the pointer parameter, to a specified bytes size through size parameter and a new pointer to the block is returned.

    20. What is a template? 
    Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one.

    21. What are the main differences between procedure oriented languages and object oriented languages? 
    With Object-oriented Programming, designs can be reused and recycled throughout the program where Procedural Programming is usually not able to do this. Additionally planning out the process of the design is much different with Procedural Programming than it is with Object-oriented Programming.

    22. What is R T T I ? 
    (RTTI) refers to a C++ mechanism that exposes information about an object's data type at runtime. Run-time type information can apply to simple data types, such as integers and characters, or to generic types

    23. What are generic functions and generic classes? 
    Typically a generic function is an instance of a class that inherits both from function and standard-object. Thus generic functions are both functions (that can be called with and applied to arguments) and ordinary objects.

    24. What is namespace? 
    A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.

    25. What is the difference between pass by reference and pass by value? 
    Passing by reference means the called functions' parameter will be the same as the callers' passed argument (not the value, but the identity - the variable itself). Pass by value means the called functions' parameter will be a copy of the callers' passed argument.

No comments:

Post a Comment