Académique Documents
Professionnel Documents
Culture Documents
1. const:
const char* p=char const *p //the content that the pointer point to is constant,
which can’t be change.
Char *const p//it’s a const pointer, the pointer can’t not be changed.
The variable with const cannot be changed, which can improve the
robustness of program.
2. Abstract class
The abstract class is a class that has pure virtual function. The pure virtual
function is “virtual fun()=0”; This kind of class can supply an interface, just
like the interface of java. But we cannot create an object of it.
3. Destructor
The Destructor is used to deallocate the memory and cleanup for a class
object and its class members when the object is destroyed. Usually, we
define the destructor as a virtual one in the base class, which can ensure
the correct procedure of the destructing.
4. Friends are functions or classes declared with friend key words. We can
use this to access the protected and private part of a class.
5. Constructor is used to initialization. But constructor can’t be declared as a
virtual type.
6. In inheritance, the sequence of calling destructor is first derived class,
second base class. The sequence of calling constructor is first base class,
and then derived class.
7. How to prevent the automatic(implicit) conversion of constructor?
Use explicit key words to prevent this.
8. Int i=0, j=0, k=0; if(++i||j++||++k){} the result of i,j,k?
i=1,j=0,k=0.
9. The function in a class that be access as a callback function must be a
static function.
10. Virtual function: a function of a class that can be redefine in another class
is virtual function. This function must be with a virtual keyword.
Virtual inheritance is used to ensure there is only one copy of base class
when more than one derived class inherit from the base class. The base
class that is virtually inherited is virtual base class.
11. Reference vs Pointer
Reference is an alias, which can’t be assign null value. Pointer is a
variable that stores the reference of another variable.
Reference must be initialized.
12. Function overloading: The function that has same function name but with
different number and type of parameters.
13. The merit of object-oriented is inheritance, polymorphism, package.
14. The difference between class in c++ and the structor in c?
The class in c++ has member protection. And it also has the
characteristics of the object-oriented programming, such as inheritance
and polymorphism.
15. The global variables vs local variables
The lifetime of GV is the running time of the whole program. The lifetime of
LV is the time of calling local function or procedure. Allocating memory for
GV happens after calling main function, moreover, if GV is static type, the
time that allocating memory will before calling main function. Allocating
memory for LV is dynamic in user stack.
16. The ifdef/define/enddef in header file is used to prevent the header file to
be referenced duplicate.
17. Extern: if you want to reference the header or function in c, you must use
extern. Eg: extern “c ”{include” cExample.h” }
18. Static: a. the static variable in a function will not be changed, when the
function is being called.
b. the static variable declared in a module but outside function can only be
called by any function in the module. In other words, it’s a local global
variable.
c. the static function declared in a module can only called by other function
in this module.
19. What is the difference between private and protected.
Private variables, are variables that are visible only to the class to which they
belong. Whereas Protected are visible both class to which the belong as well
as to its subclasses.
Computer Architecture
since local variables are stored in stack,hence,decalre a local variable & maintain pointer to
it.Now,increment pointer by one and print the address & compare with the previous
value.if +ve then stack grows up else grows down
15.heap vs stack.
Heap—dynamic memory allocation, not scope dependent
Stack—also means buffer, automatic memory allocation, scope dependent.
When certain part of the heap is freed while its neighboring memory pieces
are still in use, a hole or fragment is created in a heap. When two neighboring
memory pieces in a heap freed at different time, the OS may not be able to
merge them into a large piece.
When allocating memory in a heap where fragmentation exists, newly
allocated memory pieces can only fit in those fragments that are equal to
larger than the size to allocate.
19. Explain how memory allocation works in c++. Where is the stack vs the
heap used?
Global, static variables---data segment
Local variables—in stack---function call another function.
Dynamically allocated --- heap--- such as malloc, new()
20. Function of MMU(memory management unit)
MMU is hardware component responsible for handling accesses to
memory requested by the CPU. Its function include translation of virtual
addresses to physical addresses, memory protection, cache control, bus
arbitration, bank switching.
21. Write-back Cache vs Write-through Cache; when is a word evicted in
write-back cache?
Write-through Cache: Every write access to the cache causes a write to
main memory.
Write-back Cache: Every write access to the Cache is not immediately
written into main memory. Cache will write (dirty locations) into main
memory some time later.
When a cache miss happens, a cache entry is evicted.
Replacement policy: when a memory location is not present in the cache
(cache miss), the cache creates a new entry. If all cache entries are used,
the cache has to decide which existing entry should be removed to make
room for cache miss.
In a write-back cache, cache often requires 2 accesses to main memory.
First access is to write the dirty locations of evicted entry into main
memory. Second access is to read cache missed memory location from
main memory to cache
22. suppose a code in Verilog is synthesis by using a tool lets say Xilinx then
what would if-elseif-else would result in?
It will be realized in logic element like multiplexers.
23. What is Branch Target Buffer? How is it helpful in reducing bubble cycles
in case of branch misprediction?
Branch target buffer is a buffer that is index by the branch instruction
address with a tag for remaining bits. The info stored can be branch taken
history and target address so it doesn’t have to recompute.
24. Cache coherency—MESI/MSI protocol
MESI—Cache coherency protocol used in x86 processor. M-modified, E-
Exclusive, S-Shared, I-Invalid
25. Interrupt handler
A function registered to service a interrupt of a device.
26. Compiler interprets the program code into machine executable instructions
27. How much memory will the following code take:
Void example{ int bytes; virtual functionName{};}
On a 32bit machine it will be 8 bytes(4 for int+4 for vptr)
On a 64bit machine it would be 16(4 for int+4 padding+8 for vptr)
28. What is buffer overflow and how do you exploit it?
Buffer overflow is an anomalous condition where a process attempts to
store data beyond the boundaries of a fixed length buffer. Buffer overflows
may cause a process to crash to produce incorrect results.
Sufficient bounds checking by either the programmer or the compiler can
prevent buffer overflows.
29. What are memory leaks
When you create objects and do not destroy after its scope is over, the
memory occupied by object is not freed. As the program is run over and
over again, more and more memory becomes captive, thus leaving no
memory to run any further application. This is memory leak.
30. The process vs Thread
Process is the execution state of a program. An application may consist of
a single process or multiple processes. A thread is a path of execution with
in a process. There can be one or more threads running within a process.
31 page fault
page is a fixed-length block of memory that is used as a unit of transfer
between physical memory and external storage like a disk, and a page fault is
an interrupt (or exception) to the software raised by the hardware, when a
program accesses a page that is mapped in address space, but not loaded in
physical memory.
32 Thrashing
Thrash is the term used to describe a degenerate situation on a computer
where increasing resources are used to do a decreasing amount of work. In
this situation the system is said to be thrashing. Usually it refers to two or
more processes accessing a shared resource repeatedly such that serious
system performance degradation occurs because the system is spending a
disproportionate amount of time just accessing the shared resource.
Resource access time may generally be considered as wasted, since it does
not contribute to the advancement of any process. In modern computers,
thrashing may occur in the paging system (if there is not ‘sufficient’ physical
memory or the disk access time is overly long), or in the communications
system (especially in conflicts over internal bus access), etc.
33. Write a step by step execution of things that happen after a user presses
a key on the keyboard. Use as much detail as possible.
A. The keyboard sends a scan code of the key to the keyboard controller
(Scan code for key pressed and key released is different).
2. The keyboard controller interprets the scan code and stores it in a buffer.
3. The keyboard controller sends a hardware interrupt to the processor. This
is done by putting signal on “interrupt request line”: IRQ 1.
4. The interrupt controller maps IRQ 1 into INT 9.
5. An interrupt is a signal which tells the processor to stop what it was doing
currently and do some special task.
6. The processer invokes the “Interrupt handler”. CPU fetches the address of
“Interrupt Service Routine” (ISR) from “Interrupt Vector Table” maintained by
the OS (Processor use the IRQ number for this).
7. The ISR reads the scan code from port 60h and decides whether to
process it or pass the control to program for taking action.
34. Write a program to find whether a machine is big endian or little endian.
#define BIG_ENDIAN 0
#define LITTLE_ENDIAN 1
int TestByteOrder() {
short int word = 0x0001;
char *byte = (char *) &word;
return (byte[0] ? LITTLE_ENDIAN : BIG_ENDIAN);
}
Career:
准备下关于过去做过的东西!
What challenges did you encounter in the past and how you resolve it.