Random Jokes…

Infinite Loop
A mathematician, a physicist, an engineer, and a programmer were discussing the theorem that all odd numbers are prime.

Mathematician: 3 is prime, 5 is prime, 7 is prime, 9 is not prime. The theorem is false.

Physicist: 3 is prime, 5 is prime, 7 is prime, 9 is not, 11 is…. The theorem is true, within experimental error.

Engineer: 3 is prime, 5 is prime, 7 is prime, 9 is prime, 11 is prime…. The theorem is true.

Programmer: 3 is prime, 3 is prime, 3 is prime….

Computer Contrast
In Computer Heaven:
The management is from Intel,
The design and construction is done by Apple,
The marketing is done by Microsoft,
IBM provides the support,
Gateway determines the pricing.

In Computer Hell:
The management is from Apple,
Microsoft does design and construction,
IBM handles the marketing,
The support is from Gateway,
Intel sets the price.

Drug dealers VS Software developer 🙂
Drug dealers:

  • Refer to their clients as “users”.
  • “The first one’s free!”
  • Have important South-East Asian connections (to help move the stuff).
  • Strange jargon: “Stick”, “Rock”, “Dime bag,” “E”.
  • Realize that there’s tons of cash in the 14- to 25-year-old market.
  • Job is assisted by industry’s producing newer, more potent mixes.
  • Often seen in the company of pimps and hustlers.
  • Their product causes unhealthy addictions.
  • Do your job well, and you can sleep with sexy movie stars who depend on you.
  • Software developers:

  • Refer to their clients as “users”.
  • “Download a free trial version…”
  • Have important South-East Asian connections (to help debug the code).
  • Strange jargon: “SCSI”, “ISDN”, “Java”, “RTFM”
  • Realize that there’s tons of cash in the 14- to 25-year-old market.
  • Job is assisted by industry’s producing newer, faster machines.
  • Often seen in the company of marketing people and venture capitalists.
  • Their product causes unhealthy addictions – DOOM. Quake. SimCity. Duke Nukem 3D.
  • Damn! Damn! DAMN!!!
  • Simple and Complex C++ interview questions and answer

    These are some simple C++ interview questions collected from differ books , notes and Blogs. Please give feedback via comments 🙂

    What are recursive functions? What are the advantages and disadvantages of Recursive algorithms?

    A recursive function is a function which calls itself.

    The advantages of recursive functions are:

    -Avoidance of unnecessary calling of functions.

    -A substitute for iteration where the iterative solution is very complex. For example to reduce the code size for Tower of Honai application, a recursive function is bet suited.

    – Extremely useful when applying the same solution

    The disadvantages of Recursive functions:

    -A recursive function is often confusing.

    -The exit point must be explicitly coded.

    -It is difficult to trace the logic of the function.

    What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.

    An internal iterator is implemented by the member functions of the class which has the iteration logic.

    An external iterator is implemented by a separate class which can be attached to the object which has iteration logic.

    The advantage of external iterator is that, many iterators can be made active simultaneously on the existing or same object.

    Describe the virtual function and virtual function table.

    A virtual function in C++ is

    – A simple member function of a class which is declared with “virtual” keyword

    – It usually performs different functionality in its derived classes.

    – The resolving of the function call is done at run-time.

    Virtual Table:

    A virtual table is a mechanism to perform dynamic polymorphism i.e., run time binging. Virtual table is used to resolve the function calls at runtime. Every class that uses virtual functions is provided with its own virtual functions.

    Every entry in the virtual table is a pointer that points to the derived function that is accessible by that class. A hidden pointer is added by a compiler to the base class which in turn calls *_vptr which is automatically set when an instance of the class is created and it points to the virtual table for that class.

    Question – What is copy constructor?

    Answer – A copy constructor is a special type of constructor that is used to create an object as a copy of an existing object. It takes an argument which is a reference to the object to be copied.

    Question – When do you use :: Operator in C++?

    Answer – :: is the scope resolution operator. When local variable and global variable are having same name, local variable gets the priority. C++ allows flexibility of accessing both the variables through a scope resolution operator.

    Question – Define reference variable in C++.

    Answer – A reference variable is just like pointer with few differences. It is declared using & operator. A reference variable must always be initialized. The reference variable once defined to refer to a variable can’t be changed to point to other variable. You can’t create an array of references the way it is possible with pointer.

    Question – What is const qualifier?

    Answer – const qualifier is used to specify the variable that can’t be change throughout the program. Variable with const qualifier is often named in uppercase.

    Question – When do you use bool data type?

    Answer – The bool data type can take only two values true or false.

    Question – What is function overloading in C++?

    Answer – You can have 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.

    Question – Explain Object oriented programming.

    Answer – Object oriented programming uses objects to design applications. This technique is designed to isolate data. The data and the functions that operate on the data are combined into single unit. This unit is called an object. Each object can have properties and member functions. You can call member function to access data of an object. It is based on several techniques like encapsulation, modularity, polymorphism, and inheritance.

    Vector vs. Map

    In a vector, all the elements are in a sequence whereas Map stores element in the form of a key-value association pair.

    Define namespaces

    Namespaces is used to group together all the related classes.

    To use namespace, using keyword or scope resolution operator can be used.

    namespace emp

    {

    class Manager

    {

    public:

    static void showDetail()

    {

    }

    };

    }

    To use

    emp::Manage::showDetail();

    or

    using namespace emp;

    Manager::showDetail();

    Question – Explain the difference between Struct and class in terms of Access Modifier.

    Answer

    All members of a class are private by default, whereas fields of a struct are public. Default access of a base class is private for classes and public for structures.

    For Example

    struct Emp {

    char Name[20]; // Here Name variable is public

    };

    What is the difference between an inspector and a mutator?

    An object’s state is returned without modifying the object’s abstract state by using a function called inspector. Invoking an inspector does not cause any noticeable change in the object’s behavior of any of the functions of that object.

    A mutator, on the other hand, changes the state of an object which is noticeable by outsiders. It means, it changes the abstract state of the object.

    The following code snippet depicts the usage of these two functions:

    class ShoppingCart {

    public:

    int addItem(); //Mutator

    int numItems() const; //Inspector

    };

    The function addItems() is a mutator. The reason is that it changes the ‘ShoppingCart’ by adding an item.

    The function numItems() is an inspector. The reason is that it just updates the count of number of items in the ‘ShoppingCart’. The const declaration followed by int numItems() specifies that numItems() never change the ‘ShoppingCart’ object.

    Question – Explain typecasting.

    Answer – Typecasting enables data type conversion. C++ supports Implicit conversions and Explicit conversion. Implicit conversions automatically performed when a value is copied to a compatible type. If there is an operation between an int and a float, the int is promoted to float before performing operation.

    You can cast types explicitly as follows.

    int i, j, k;

    k = i * long(j);

    Question – Define default constructor.

    Answer – Default constructor is the constructor with no arguments or all the arguments has default values.

    Question – Define abstraction.

    Answer – The process of hiding unnecessary data and exposing essential features is called abstraction. Abstraction is separating the logical properties from implementation details.

    Question – What is overriding?

    Answer – Defining a function in the derived class with same name as in the parent class is called overriding. In C++, the base class member can be overridden by the derived class function with the same signature as the base class function. Method overriding is used to provide different implementations of a function so that a more specific behavior can be realized.

    Question – What is copy constructor?

    Answer – A copy constructor is a special type of constructor that is used to create an object as a copy of an existing object. It takes an argument which is a reference to the object to be copied.

    What is an abstraction and why is it important?

    Abstraction is to specify what to do (the necessary details) but not how to do (all details). For example, monitor information like size, screen type, power switches are specified for abstraction. But the inner parts and the functionality need not be known. In other words, making the details available for the user does matters.

    For example, Employee class has a method calculateSalary() which receives the ‘empid’ as parameter and returns the salary of the employee concerned. The user who invokes the calculateSalary() method does not concerned about how the salary calculated. So, abstraction specifies to expose only the details which are concerned with the user.

    Abstraction is important because, the code reusability is one of the benefits to the user. There is flexibility to implement the business logic for various objects which accesses the method. In the above example, salaries of employees of various cadres can use the neither same method with minor nor changes.

    What is the difference between an inspector and a mutator?

    An object’s state is returned without modifying the object’s abstract state by using a function called inspector. Invoking an inspector does not cause any noticeable change in the object’s behavior of any of the functions of that object.

    A mutator, on the other hand, changes the state of an object which is noticeable by outsiders. It means, it changes the abstract state of the object.

    The following code snippet depicts the usage of these two functions:

    class ShoppingCart {

    public:

    int addItem(); //Mutator

    int numItems() const; //Inspector

    };

    The function addItems() is a mutator. The reason is that it changes the ‘ShoppingCart’ by adding an item.

    The function numItems() is an inspector. The reason is that it just updates the count of number of items in the ‘ShoppingCart’. The const declaration followed by int numItems() specifies that numItems() never change the ‘ShoppingCart’ object.

    What is abstraction?

    It is the process of hiding unwanted details from the user.

    What are the advantages of inheritance?

    Code reusability

    Saves time in program development.

    What is a conversion constructor?

    It is a constructor that accepts one argument of a different type.

    What is a default constructor?

    A constructor that has no argument is a default constructor.