Vous êtes sur la page 1sur 8

C++:

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

1. What is virtual memory? What is pre-requisite in Hardware for supporting


virtual memory? What is TLB?
Virtual memory is extension of the physical memory. Virtual memory
describes the whole memory space available on the computer, which can
be much greater than the physical memory by utilizing storage outside of
physical memory to extend the address space. Typically, Virtual memory is
implemented by using hard disk space to store parts of the memory space.
The re-requisite is that CPU should have a MMU to support virtual to
physical address translation.

TLB is a tool that caches translations of address space to the appropriate


location that this address space is actually stored(ram,disk). It saves on
computational work to convert the virtual address space (what the program
uses) to the physical address- that the operating system uses to then
retrieve things from actual ram or from a specific location in a disk page
file.
2. How does malloc work?
Malloc() is a standard library function internally using brk() system call.
And brk in turn sets the end of the data segment to the value specified by
addr, when the value is reasonable, the system has enough memory, and
the process does not exceed its maximum data size.
Malloc takes one argument, calloc takes two
Malloc does not initialize the memory, but calloc initialize it to zero.
3. Big-endian vs little-endian
In big endian, the most significant byte is stored at the memory address
location with the lowest address.. Just like the left to right reading order.
Little endian is the reverse; the most significant byte is stored at the
address with the highest address. CPU decide endianess. Intel processor
supports little endian and sparc processor supports big endian.
Little endian is useful in increment and decrementing the values.
Big-endian is useful in comparison. Moreover, we can stop at the point
where mismatch occurs.
4. What is Amdhal’s law?
It states that the performance improvement to be gained by using some faster
mode of execution is limited by the fraction of time the faster mode can be
used.
Overall speedup= (1/(1-f)+(f/s))
Where f—fraction of benchmark that is improved
s—Speed of the enhanced portion
5. I want to create a LRU such that push,pop, and find min are done in
constant time, how to do this?
I think the solution I s to have a list sorted by recently used order. So, there
will be MRU on one end and LRU on other.
Push: add to MRU position, head of queue: const time
Pop: delete from LRU position, tail of queue:const time
Find min:return LRU:const time
6. Memory mapped I/O vs DMA
Memory mapped I/O allows the CPU to control hardware by reading and
writing specific memory addresses. Usually this would be used for low-
bandwidth operation such as changing control bits.
DMA allow hardware to directly read and write memory without involving the
CPU. Usually this would be used for high-bandwidth operations such as disk
I/O or camera video input.
The memory allocated to user level buffer/pointer can be accessed by drivers by using DMA .
6. What does wmb instruction do?
Wmb is Write Memory Barrier. It can guarantees that all previous store
instructions access memory before any store instructions issued after the
wmb instruction.
7.Write a c function return whether the stack grows up or grows down.

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

8. What happens when a function is called from another function.


a. All local variables are reserved in stack.
b. ES register such like return address is saved
c. Jump to the function address to fetch the code
d. when function is created, the local variables in the function is created in
stack area too.
e. when it’s done, it goes back to the return address saved in ES.
d. Keep going on the caller function.
9. If an application is running, but it does not produce output; memory utilization is
constant, cpu utilization goes down to 0; what will be the problem.
Thrashing or Deadlock.
10. What is the size of VPTR. Where is it stored?
When a class object is created, vptr is set to point to the virtual table for that
class. So VPTR should be stored in object memory
Size of vptr depends of machine.. for 32 bit machine it is 4 bytes and for 64 bit
machine it is 8 bytes
11. Will malloc work if RAM is 5MB, 1st two MBs are full and the 4th MB is full
and it has to allocate 1.5 MB of data.
.Malloc always allocates bytes from the heap which is present in the virtual
memory. The programmer does not have any rights to access RAM directly
through program. Malloc requests a contiguous block in virtual memory. This
block can be mapped into physical memory in many ways. So, malloc will
always work irrespective of the usage of RAM.
12 Where are static variables stored?|
Static variables are stored in BSS(Block Started by Sybmbol) segment, BSS
is part of Data Segment..
13. Write a function to check if a stack grows up or down.

void foo(char *a);


main()
{
char str=' ';
char *a=&str;
foo(a);
}

void foo(char *a)


{
char str=' ';
char *b=&str;
if(a>b)
printf("down");
else
printf("grow");
}

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.

17.Big cache vs Small cache


Bigger cache increases hit time, which will make the access slow for the
already present element in cache, but it reduces miss rate as more of data
can be put into the cache.
Smaller cache has a less hit time, hence can operate fast. But it increases
miss rate as less date can be accompanied in cache.

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);
}

35. What's the disadvantage of having a cache with more associativity?


Complex circuitry. More power consumption. Longer hit time.

Career:

Why do you want to work in AMD?|

准备下关于过去做过的东西!

What kind of role do you describe yourself in a team?

What challenges did you encounter in the past and how you resolve it.

Vous aimerez peut-être aussi