27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 16 | Low Level<br />

How to Approach:<br />

Many c<strong>and</strong>idates find low level problems to be some of <strong>the</strong> most challenging. Low level<br />

questions require a large amount of knowledge about <strong>the</strong> underlying architecture of a system.<br />

But just how much do you need to know? The answer to that depends, of course, on<br />

<strong>the</strong> company. At a typical large software company where you’d be working on desktop or<br />

web applications, you usually only need a minimum amount of knowledge. However, you<br />

should underst<strong>and</strong> <strong>the</strong> concepts below very well, as many interview questions are based off<br />

this information.<br />

Big vs Little Endian:<br />

In big endian, <strong>the</strong> most significant byte is stored at <strong>the</strong> memory address location with <strong>the</strong><br />

lowest address. This is akin to left-to-right reading order. Little endian is <strong>the</strong> reverse: <strong>the</strong><br />

most significant byte is stored at <strong>the</strong> address with <strong>the</strong> highest address.<br />

Stack (Memory)<br />

When a function calls ano<strong>the</strong>r function which calls ano<strong>the</strong>r function, this memory goes onto<br />

<strong>the</strong> stack. An int (not a pointer to an int) that is created in a function is stored on <strong>the</strong> stack.<br />

Heap (Memory)<br />

When you allocate data with new() or malloc(), this data gets stored on <strong>the</strong> heap.<br />

Malloc<br />

Memory allocated using malloc is persistent—i.e., it will exist until ei<strong>the</strong>r <strong>the</strong> programmer<br />

frees <strong>the</strong> memory or <strong>the</strong> program is terminated.<br />

void *malloc(size_t sz)<br />

Malloc takes as input sz bytes of memory <strong>and</strong>, if it is successful, returns a void pointer which<br />

indicates that it is a pointer to an unknown data type.<br />

void free(void * p)<br />

Free releases a block of memory previously allocated with malloc, calloc, or realloc.<br />

8 1<br />

<strong>Cracking</strong> <strong>the</strong> <strong>Coding</strong> <strong>Interview</strong> | Knowledge Based

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!