Some real C ++ interview questions

So, I gathered some interviews that I was asked for. I answered some and noted the answers to those that I could not. Some questions are not specific and are general. Everyone can add their contribution to the questions. No obligation to follow the answers I wrote!

Q1: What will be the size of the pointer to the 2-bit system and 16-bit system?
A: 2 bits and 2 bytes

Q2: Why do we need OOP / classes when in C we had structures and could achieve the same?
A: Leave this to SO users to reply!

Q3: If you were told to divide the program into separate parts of the embedded system, what would they do?
A: IO part and processor part

Q4: What are some hardware level advantages when using threads? Any of them gives one example for a single processor (single core). A: One thread will make some crunchy numbers, others just live in milliseconds. signal an event to read the hard drive.

Q5: If we had a pointer char* p = NULL , what would print cout<<sizeof(*p) ? A: char size, not char* . This means the amount of memory it points to, not the size of the pointer itself

Q6: What functions point to pointers to objects in a virtual table? A: Virtual Functions

Q7: How would you calculate how many threads a program requires for optimal performance for a single processor (single core)? Will you do a physical test or can you automate your program? Give an example. Or both that, and another, an example.
A: SO users will answer here!

Q8: If a virtual function (not pure) is an inheritance, it is not implemented in a derived class. Now, if I have a base class pointer to a derived class object, then make a call to baseObject->function() , what will happen? Will there be any problems at any point in compile time / runtime? A: No. :)

+8
c ++
source share
2 answers

A1 2 bits and 16 bits is the obvious answer. I ask for clarification as "in technical terms, what exactly do you mean 2-bit system" to make sure.

A2 This is OOP 101 stuff ... the short answer may be "Because classes allow you to inherit, and inheritance allows many useful paradigms (most importantly, polymorphism) that reduce code complexity."

A3 I'm afraid that I will not consider your answer to be correct. You should definitely ask โ€œwhat programโ€ to get the general idea: is this a service? a script? desktop application? Without additional input, I would answer "split into user interface and business logic."

A4 At the hardware level, threads allow your application to better utilize your hardware resources (for example, multiple processor cores). An example would be any separation and rest algorithm, where the divided work can be performed in parallel across several threads (for example, many sorting algorithms). Again, I think your answer is wrong.

A5 That's right.

A6 That's right.

A7 . First of all: see if the program is connected to the CPU (some quick and dirty measurements will tell you about this). If it is not connected to the CPU, then most likely a single thread will be enough. If so, then you want to use as many threads as possible (which means as many as parts into which you can divide your work), up to the number of threads that your equipment can execute at the same time.

A8 Bugfix: no problem, base class implementation will be called.

+7
source share

Um ... not C ++ for sure, but this:

Imagine that you have two hosts, a provider, their router, administrators and a lot of beer. You want telnet one host from another using 192.168.0.5 (another private host address). Is it possible?

A: Yes, of course, it is possible. Everything is possible with admins when you have a lot of beer.

(This is a real question that I received in an interview once in my life. Well, some good humor during the interview can help a person relax and, well, seem to make the atmosphere in the interview easier, you know what I mean. )

It should be a Wiki community, right? And there is a duplicate of this somewhere, if I'm not mistaken.

-one
source share

Source: https://habr.com/ru/post/650426/


All Articles