C++ interview question involving class pointers
Lets say there is a base class pointer which is pointing to a base class object: baseclass *bptr; bptr= new baseclass; now if i do bptr= new derived; what is the problem here? ...
Lets say there is a base class pointer which is pointing to a base class object: baseclass *bptr; bptr= new baseclass; now if i do bptr= new derived; what is the problem here? ...
I'm about to branch out into taking on some contracts on the side. What would be some good questions to ask of a potential client during a first meeting? I've thought of a few things that seem pretty obvious: * What is the project? * What are the deadlines? * What's the budget? * What/how do they want me to deliver the completed work? ...
What kind of things would you not store in stored procedures? ...
Spent some time searching, couldn't find exactly what I'm after. We like giving hands-on programming exercises as part of the interview process. The interviewee gets a laptop, with the editor and compiler of his choice. He or she then get a programming exercise and has about an hour to code it. Depending on the nature of the question, i...
HI everyone, during the various stages of compilation in C or C++, i know that an object file gets generated. i.e., any_name.o file. what does thos .o file contain actually. i cant open it since its a binary file. Could anybody please help me? are the contents of the object file mainly Dependant on the compiler which we use on unix? ...
I am aware of the singleton pattern in C++, but how do you get two instances of an object? Is there any such pattern where we could easily get two objects? For the logic I could think of is that I can change the singleton pattern itself to have two objects created inside the class. This works, but if the requirement grows like if I need...
Hello All.... I am just refreshing the oops features of the java. So, I have a little confusion regarding inheritance concept. For that I have a following sample code : class Super{ int index = 5; public void printVal(){ System.out.println("Super"); } } class Sub extends Super{ int index = 2; public void pr...
I'm studying for upcoming interviews and have encountered this question several times (written verbatim) Find or determine non existence of a number in a sorted list of N numbers where the numbers range over M, M >> N and N large enough to span multiple disks. Algorithm to beat O(log n); bonus points for constant time algorithm. F...
I was asked this crazy question. I was out of my wits. Can a method in base class which is declared as virtual be called using the base class pointer which is pointing to a derived class object? Is this possible? ...
If a std::set or std::list contains a sequence of natural numbers (1, 2, 3..). would there be a function in standard library to find the missing number? ...
How does a computer perform a multiplication on 2 numbers say 100 * 55. My guess was that the computer did repeated addition to achieve multiplication. Of course this could be the case for integer numbers. However for floating point numbers there must be some other logic. Note: This was asked in an interview. ...
Hi, I came across this problem in an interview website. The problem asks for efficiently implement three stacks in a single array, such that no stack overflows until there is no space left in the entire array space. For implementing 2 stacks in an array, it's pretty obvious: 1st stack grows from LEFT to RIGHT, and 2nd stack grows fro...
How to create a function, which on every call generates a random integer number? This number must be most random as possible (according to uniform distribution). It is only allowed to use one static variable and at most 3 elementary steps, where each step consists of only one basic arithmetic operation of arity 1 or 2. Example: int myr...
I was asked this question recently during my job interview, and I couldn't answer it. So, what is the most used pattern in java.io and how is it used? What are other patterns used in common java libraries? ...
Note: This was an interview question and may not have an actual use case currently The question was to design a class that can store numbers which are very very large say each number can have 100 digits. This new class is a datatype like int. What are the different types of constructors, overloads and other functions that you would wri...
How can late binding can be achieved in c language? can anybody please provide an example. i think it can be achieved using dlopen and dlsym but i am not sure about it.please correct me if i am wrong! ...
If you were tasked with hiring some new programmers for your business, and had the choice to only pick from one of the approaches listed below, what approach would you take and why? Approach 1: Asking several question about the syntax of a particular language that can be looked up in a book. You know, questions like what is the diffe...
An interviewer recently asked me this question: given 3 boolean variables a, b, c, return true if at least 2 out of the 3 are true. My solution follows: boolean atLeastTwo(boolean a, boolean b, boolean c) { if ((a && b) || (b && c) || (a && c)) { return true; } else { return false; } } He said that this can be improved ...
This is an interview questions. I tried hard to come up with my desired solution, but no success yet! An approach of O(n^2) time is pretty obvious with O(1) space, where n is the length of string/ total number of URLs. An O(n) solution can be achieved which requires additional space. In the case of non-repeating first character in a st...
Here is an interview question that I saw on some forum. I've been trying to figure out how it works but I don't quite get it. Could somebody explain how it works? Q: Given a pointer to member a within a struct, write a routine that returns a pointer to the struct. struct s { ... int a; … }; struct s *get_s_ptr(int *a_ptr) ...