Pointer job interview questions involving C++ pointers and raw pointers

(Last Updated On: May 17, 2010)

Pointer job interviews involving C++ pointers and raw pointers
The general difference between a reference and a pointer is that pointers can be null while references cannot be. Also, references needed to be initialized when created, cannot reseat one reference to an object, and cannot take a reference of a reference, but a pointer of pointer is possible. References should be used to define ‘attractive’ interfaces while pointers should be used to implement data structures and implement algorithms.
Shallow copy versus deep copy
Shallow copy means copy each bit of one member block to another. Also, if pointers are involved so new memory location will be created and data is copy into that location.
A deep copy (also known as a hard copy) involves recursively copying variables in a nested structure or in a nested object. This also involves copying from one structure to another if there are pointers in the structure, then the second pointer will point the same as the first one. This will copy all fields and also makes copies of dynamically allocated memory pointed by the fields. In order to deep copy, you must create a copy constructor which will overload the assignment operator otherwise it will copy and point to the original with disastrous results.
The difference between calloc and malloc are:
There are 2 arguments needed for calloc while malloc only needs one. The initializing of memory in calloc is zero.
Malloc reduces the need to request more memory from the operating system since it is done on a user by user basis. It recycles the freed memory space. When pointers are created and free ( pointer) is called, the header and foot are looked at by the memory allocator. The header contains information on necessary items including the size of space taken up, status if the memoery block is freed or allocated, and know if it can be removed or not.
When pointers are allocated, two bytes are used with the size of the memory block. The memory block can be assigned based on best fit or worst fit. This free memory list cannot a single linked list. This linked ist could be a balanced tree.
Sizes of memory could be:
Char a[] = “ “; could be two bytes while
Char b[10] would be 10.
a will contain two bytes where one is null and the other is ‘\0’. The trick is to remember that it will allocated to characters to this array. In short, a would be whatever is in the quotes plus a null characters as well.
Also, if you do char *c, size would be 4 in 32 bit systems but will be 8 in 64 bit systems so if you do:
b=c; size would become 4 as well.
Also, note char a[]=”hello” will be six bytes while char *P=”Hello” will result in four bytes.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
This entry was posted in Quant Development and tagged , , , , on by .

About caustic

Hi i there My name is Bryan Downing. I am part of a company called QuantLabs.Net This is specifically a company with a high profile blog about technology, trading, financial, investment, quant, etc. It posts things on how to do job interviews with large companies like Morgan Stanley, Bloomberg, Citibank, and IBM. It also posts different unique tips and tricks on Java, C++, or C programming. It posts about different techniques in learning about Matlab and building models or strategies. There is a lot here if you are into venturing into the financial world like quant or technical analysis. It also discusses the future generation of trading and programming Specialties: C++, Java, C#, Matlab, quant, models, strategies, technical analysis, linux, windows P.S. I have been known to be the worst typist. Do not be offended by it as I like to bang stuff out and put priorty of what I do over typing. Maybe one day I can get a full time copy editor to help out. Do note I prefer videos as they are much easier to produce so check out my many video at youtube.com/quantlabs