Posts

Showing posts with the label Interview Questions

Advance Interview Ask In C++ Interview #3

  How to delete array of objects in C++? Proof by C++ code for proper deletion Answer includes how to delete array of objects in C++ created dynamically with C++ code example with proof. In other words, delete array of pointers to objects in c++. Interview Question: Write C++ code to create an array of objects using new keyword and delete these objects. Also, proof that all the objects are deleted properly. Answer: We know that when we create an object of a class dynamically from heap memory using new keyword, then we must delete it explicitly to avoid memory leaks in C++ programs after we are done with its operations. Let’s take below class Pen as an example. class Pen { public: Pen() { cout << "Constructor..." <<endl; } ~Pen() { cout << "Destructor...!" <<endl; } void write(){ cout << "Writing...!" <<endl; } }; Below is an example, how we create an object ...

Advance Interview Ask In C++ Interview #2

  What is virtual destructor in C++? Why do we need virtual destructor? Answer includes what is virtual destructor in C++ with example and use of it or why do we need virtual destructor in C++ object oriented programming. Note that in an interview, if it asked about virtual destructors then don’t forget to answer when to use virtual destructor in C++ class. Also, note that there is no  concept of virtual constructor in C++ programming. Answer:  Virtual destructors maintains the hierarchy of calling destructors from derived to base class. A class must have a virtual destructor if we hit below criteria. Derived class object using a pointer to base class and deleting base class pointer. For example Base * p = new Derived (); // up casting Delete P; If we don’t make base class destructor virtual, it will not call derived class destructor on above mentioned criteria. For example class Base{ public: ~Base(){cout<<"Base class destructor..."<<"\n";} //not virt...

Advance Interview Ask In C++ Interview #1

  A good interview question based on a C++ polymorphism in oops C++ Technical Interview Question on polymorphism in oops Write a complete class stating function overriding feature in C++ Show the function call in main program. Explain the concept of function overriding. Take example of drawing multiple shapes e.g. circle and rectangle etc. Interviewer Intent: You know the concept and syntax of function overriding in C++ you can write class and program. If you follow best coding practice and the things you care when write the code. NOTE:  As per question criteria, we will write code using interface, but, to describe the concept a basic example will be covered first. Answer: Function overriding concept is run time polymorphism in oops, in which functions get resolved on run time using VTABLE (Virtual table) by compiler. If we have definition /declaration of a function in base class and want to have a definition of same function name in derive class and want to call derived funct...

C# Interview Questions Answers Part 1

Image
1.What is C#? Ans: C# is a modern, general-purpose, object-oriented programming language developed by Microsoft. C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages on different computer platforms and architectures. 2. What is Jagged Array in C#? Ans: A Jagged array is an array of arrays. You can initialize a jagged array as − int [][] scores = new int [ 2 ][]{ new int []{ 92 , 93 , 94 }, new int []{ 85 , 66 , 87 , 88 }}; Where, scores is an array of two arrays of integers - scores[0] is an array of 3 integers and scores[1] is an array of 4 integers. 3.In how many ways you can pass parameters to a method?   Ans: There are three ways that parameters can be passed to a method − Value parameters  − This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the funct...