Technical Questions

     
     
  • Program for reverse linked list.
  • How to find list is circular or not.
  • How to find middle of the node with out iterating through the number of the nodes.
  • Delete a node from Linked List.
  • How to handle dangling pointer (i.e How we can prevent dangling pointer) ?
  • What is copy constructor ?
  • Ans: 
           Copy constructor is special type of function, which will used to create a new object using existing object.
                     If there is no Copy Constructor is defined then compiler will create from own , default constructor and it will perform bit by bit copy.
  • What is assignment operator ?
  • What is malloc and calloc ?
  • What is virtual destructor ?
  • Why constructor is not virtual ?
  • Friend function with example.
  • Difference between Map and Vector ?
  • Difference between Array and Vector ?
  • Why empty class size is 1 byte ?
  • What is Casting?
  •  What is function and operator overloading?
  • Difference between Union and structure ?
  • Program for factorial using recursion.
  • Program for Dynamic Stack.
  • What is mutable??
        Ans: The keyword mutable is used to allow a particular data member of const object to be modified. This is particularly useful if most of the members should be constant but a few need to be updateable. 
Ex:
Suppose we add a "salary" member to our Employee class. While the employee name and id may be constant, salary should not be. Here is our updated class.
 
class Employee {
public:
    Employee(string name = "No Name", string id = "000-00-0000", double salary = 0) : _name(name), _id(id)
    {
        _salary = salary;
    }
    string getName() const {return _name;}
    void setName(string name) {_name = name;}
    string getid() const {return _id;}
    void setid(string id) {_id = id;}
    double getSalary() const {return _salary;}
    void setSalary(double salary) {_salary = salary;}
    void promote(double salary) const {_salary = salary;}
private:
    string _name;
    string _id;
    mutable double _salary;
}; 

Now, even for a const Employee object, the salary may be modified.
const Employee john("JOHN","007",5000.0);
....
....
john.promote(20000.0)
 
  • What is difference between const char *p, const* char p and  char* const p?
      Ans: 
           Const char* p: pointer pointing to constant char, means you can not change the content it is pointing, but yes you can change the pointer to point some other char.
           char* const p or char const* p : Both are same, means you can change the content of the address but not the address or pointer.
Note: Just to remind this for future, remember if char is near P means , you can change the pointer it is pointing to , but not the content, in other case where const is near p, that means you can not change the pointer but you can change the content where it is pointing.
  • What is explicit constructor?
         Ans:  This is to tell the compiler that certain constructor may not be using implicit cast/conversion to its class type.
Ex:
   
class Foo {
public:
  Foo(int x);
};

class Bar {
public:
  Bar(double x);
};

int main()
{
  Foo a = 42;         //OK: calls Foo::Foo(int) passing 42 as an argument
  Foo b(42);          //OK: calls Foo::Foo(int) passing 42 as an argument
  Foo c = Foo(42);    //OK: calls Foo::Foo(int) passing 42 as an argument
  Foo d = (Foo)42;    //OK: calls Foo::Foo(int) passing 42 as an argument

  Bar x = 3.14;       //OK: calls Bar::Bar(double) passing 3.14 as an argument
  Bar y(3.14);        //OK: calls Bar::Bar(double) passing 3.14 as an argument
  Bar z = Bar(3.14);  //OK: calls Bar::Bar(double) passing 3.14 as an argument
  Bar w = (Bar)3.14;  //OK: calls Bar::Bar(double) passing 3.14 as an argument 
 
  return 1;
}
 

class Foo {
public:
  explicit Foo(int x);
};

class Bar {
public:
  explicit Bar(double x);
};

int main()
{
  Foo a = 42;         //Compile-time error: can't convert 42 to an object of type Foo
  Foo b(42);          //OK: calls Foo::Foo(int) passing 42 as an argument
  Foo c = Foo(42);    //OK: calls Foo::Foo(int) passing 42 as an argument
  Foo d = (Foo)42;    //OK: calls Foo::Foo(int) passing 42 as an argument

  Bar x = 3.14;       //Compile-time error: can't convert 3.14 to an object of type Bar
  Bar y(3.14);        //OK: calls Bar::Bar(double) passing 3.14 as an argument
  Bar z = Bar(3.14);  //OK: calls Bar::Bar(double) passing 3.14 as an argument
  Bar w = (Bar)3.14;  //OK: calls Bar::Bar(double) passing 3.14 as an argument 
  return 1;
 }
Note:You can mix explicit constructors and non-explicit
constructors in the same class 
  • What is Difference between pointer and reference?
       Ans: 1) Reference is const pointer, means once intialized we can not change it.
               2) Reference can not be null, we have to initialize while creating itself, so that there is no need to check for NULLity as it wont be null, in other word in case of reference there is no need to test for NULL before use while in case of pointer we have to check.
               3) One more difference is pointer we can reassign to point to some other address, where as with reference we can not do that.
 Ex:
string str1("abc");  
string str2("xyz");  
string& ref = str1;     // ref refers to s1  
  
string *pointer = &str1;// pointer points to str1 
  
ref = str2;             // refs still refers to str1,  
                        // but str1's value is now  
                        // "xyz"  
  
pointer = &str2;        // pointer now points to str2;  
                        // str1 is unchanged 
 
 
 
  • Can we create Reference of reference variable? 
  • What is memory leak?
  • What is little endian and big endian ?
  • What is watch dog timer?
  • Difference between Semaphore and Mutex.
  • What is static ? how static is handled?
  • What is structure padding?
  • What is function pointer?
  • What is singleton? 
  • What is initialization list?
  • How virtual table and VPTR works?
  • How you can stop deriving your class?
  • What is function and class template? 
  • How to prevent Structural padding?   (Hint : using Pragma pack)
  • Write a program for reversing doubly linked list.
  • What is difference between compiler copy constructor and user created ,assignment operator.
  • Difference between Vector , List and linked list.
  • How compiler will do name mangling , which platform name mangling will not happen?
  • If in a class there is only 2 void function then what will be size of the class?
  • Can we do overriding with out Virtual?
  • Difference between 32 bit and 64 bit machine.
  • What is name hiding ?
  • What is the size of empty class and structure?
  • Ans: both are of 1 byte.
 Q: What is difference between class and structure
Ans: 1) Member of class by default private but incase of structure by default they are public.
         2) When deriving from class , by default access specifier is Private where in struct it will be public.
Ex 1:
class Base {
public:
    int x;
};
class Derived : Base { }; // is same as, class Derived : private Base {}
int main()
{
  Derived d;
  d.x = 20; // compiler error because inheritance is private, and private can not // be accessed outside the class
  return 0;
}
Ex 2:
class Base {
public:
    int x;
};
struct Derived : Base { }; // is same as struct Derived : public Base {}
 int main()
{
  Derived d;
  d.x = 20; // works fine because inheritance is public
  return 0;
}
  • MFC:
    Q 1 :What is model and modeless dialog box ? Give some examples?
    Ans:- When we create Modal Dialog Box we can't move to other windows until this dialog is closed. For eg: MessageBox, where we can't move to the other window until we press ok or cancel. 
    When we create Modeless Dilaog Box we can swap to the other windows. For eg: like a conventional window.
    Q 2:- Which are the different controls in MFC ?
    Ans:- CAnimateCtrl, CButton, CEdit, CListBox, CComboBox, CRichEditCtrl, CStatic, TreeCtrl, ToolTipCtrl, IPAddressCtrl, TabCtrl,CDa teTimeCtrl, HeaderCtrl, ListCtrl, MonthCalCtrl, OleCtrl, ProgressCtrl, ScrollBar, SliderCtrl, StatusBarCtrl, TollBarCtrl etc.,


     

No comments: