C++ interview questions
Implement itoaC++
Implementing itoa function is a popular interview question. Here’s one implementation from SAP.
char *itoa(int value)
{
int count, /* number of characters in string */
i, /* loop control variable */
sign; /* determine if the value is negative */
char *ptr, /* temporary pointer, index into string */
*string, /* return value */
*temp; /* temporary string array */
count = 0;
if ((sign = value) < 0) /* assign value to sign, if negative */
{ /* keep track and invert value */
value = -value;
count++; /* increment count */
}
/* allocate INTSIZE plus 2 bytes (sign and NULL) */
temp = (char *) malloc(INTSIZE + 2);
if (temp == NULL)
{
return(NULL);
}
memset(temp,'\0', INTSIZE + 2);
string = (char *) malloc(INTSIZE + 2);
if (string == NULL)
{
return(NULL);
}
memset(string,'\0', INTSIZE + 2);
ptr = string; /* set temporary ptr to string */
/*--------------------------------------------------------------------+
| NOTE: This process reverses the order of an integer, ie: |
| value = -1234 equates to: char [4321-] |
| Reorder the values using for {} loop below |
+--------------------------------------------------------------------*/
do {
*temp++ = value % 10 + '0'; /* obtain modulus and or with '0' */
count++; /* increment count, track iterations*/
} while (( value /= 10) >0);
if (sign < 0) /* add '-' when sign is negative */
*temp++ = '-';
*temp-- = '\0'; /* ensure null terminated and point */
/* to last char in array */
/*--------------------------------------------------------------------+
| reorder the resulting char *string: |
| temp - points to the last char in the temporary array |
| ptr - points to the first element in the string array |
+--------------------------------------------------------------------*/
for (i = 0; i < count; i++, temp--, ptr++)
{
memcpy(ptr,temp,sizeof(char));
}
return(string);
}
Hardware architecture interview questions
C++ Hardware
Are you familiar with the term MESI?
Are you familiar with the term snooping?
Describe a finite state machine that will detect three consecutive coin tosses (of one coin) that results in heads.
In what cases do you need to double clock a signal before presenting it to a synchronous state machine?
You have a driver that drives a long signal & connects to an input device. At the input device there is either overshoot, undershoot or signal threshold violations, what can be done to correct this problem?
For a single computer processor computer system, what is the purpose of a processor cache and describe its operation?
Explain the operation considering a two processor computer system with a cache for each processor.
What are the main issues associated with multiprocessor caches and how might you solve it?
Explain the difference between write through and write back cache.
What are the total number of lines written in C/C++? What is the most complicated/valuable program written in C/C++?
What compiler was used?
Have you studied busses? What types?
Have you studied pipelining? List the 5 stages of a 5 stage pipeline. Assuming 1 clock per stage, what is the latency of an instruction in a 5 stage machine? What is the throughput of this machine ?
How many bit combinations are there in a byte?
What is the difference between = and == in C?
Are you familiar with VHDL and/or Verilog?
Tricky C questions
C++
How do you write a program which produces its own source code as its output?
How can I find the day of the week given the date?
Why doesn’t C have nested functions?
What is the most efficient way to count the number of bits which are set in a value?
How can I convert integers to binary or hexadecimal?
How can I call a function, given its name as a string?
How do I access command-line arguments?
How can I return multiple values from a function?
How can I invoke another program from within a C program?
How can I access memory located at a certain address?
How can I allocate arrays or structures bigger than 64K?
How can I find out how much memory is available?
How can I read a directory in a C program?
How can I increase the allowable number of simultaneously open files?
What’s wrong with the call fopen(”c:\newdir\file.dat”, “r”)?
C++ developer interview
C++
Will the following program execute?void main()
{
void *vptr = (void *) malloc(sizeof(void));
vptr++;
}
How about this one?
void main()
{
char *cptr = 0?2000;
long *lptr = 0?2000;
cptr++;
lptr++;
printf(” %x %x”, cptr, lptr);
}Will it execute or not?
When the processor wakes up after power on, it goes to a particular memory location. What is that memory location called?
What is the difference between Mutex and Binary semaphore?
Write a program to set 2nd bit in a 32 bit register with memory location 0×2000?
C questions for a hardware engineer
C++ Hardware
What are the total number of lines written in C/C++? What is the most complicated/valuable program written in C/C++?
What compiler was used?
Have you studied buses? What types?
Have you studied pipelining? List the 5 stages of a 5 stage pipeline. Assuming 1 clock per stage, what is the latency of an instruction in a 5 stage machine? What is the throughput of this machine ?
How many bit combinations are there in a byte?
What is the difference between = and == in C?
Are you familiar with VHDL and/or Verilog?
C++ interview questions
This set of C++ interview questions was sent to TechInterviews from Australia:
What is the difference between an ARRAY and a LIST?
What is faster : access the element in an ARRAY or in a LIST?
Define a constructor - what it is and how it might be called (2 methods).
Describe PRIVATE, PROTECTED and PUBLIC – the differences and give examples.
What is a COPY CONSTRUCTOR and when is it called (this is a frequent question !)?
Explain term POLIMORPHISM and give an example using eg. SHAPE object: If I have a base class SHAPE, how would I define DRAW methods for two objects CIRCLE and SQUARE.
What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?
What are 2 ways of exporting a function from a DLL?
You have two pairs: new() and delete() and another pair : alloc() and free(). Explain differences between eg. new() and malloc()
What is a callback function. Explain in C and C++ and WIN API environment.
(From WINDOWS API area): what is LPARAM and WPARAM?
C++ notes for discussion
C++
This is not really a set of interview questions, a reader sent TechInterviews.com what looks like a copy of his notes from C++ class that describes various tricks and code for C++.
What is the output of printf(“%d”)?
%d helps to read integer data type of a given variable
when we write (“%d”, X) compiler will print the value of x assumed in the main
but nothing after (“%d”) so the output will be garbage
printf is an overload function doesnt check consistency of the arg list – segmentation fault
What will happen if I say delete this? - destructor executed, but memory will not be freed (other than work done by destructor). If we have class Test and method Destroy { delete this } the destructor for Test will execute, if we have Test *var = new Test()
pointer var will still be valid
object created by new exists until explicitly destroyed by delete
space it occupied can be reused by new
delete may only be applied to a pointer by new or zero, applying delete to zero = no FX
delete = delete objects
delete[] – delete array
delete operator destroys the object created with new by deallocating the memory assoc. with the object
if a destructor has been defined fir a class delete invokes that desructor
Read all interview questions
Some general quickies
How did you first get interested in Computer Science?
What do you like to do best related to computers now (programming, administration, testing, manage projects, etc)? What is it about that area that you specifically enjoy?
What is your strongest programming language (Java, ASP, C, C++, VB, HTML,C#, etc.)?
When is the last time you coded in C/C++?
What is the most lines of original C/C++ code you have personally written in one project?
How confident are you in your ability to write C or C++ without a reference?
Embedded firmware interview questions
Write function in C that gets array of chars, and search for the longest sequence of repeatedly 1 bits. It returns the the first bit place in the sequence and the number of 1 bits in the sequence. - (a) loop of 2^0, 2^1, … , 2^7 is done with 1<
C and C++ questions for the interview
C++
What is the output of printf(”%d”)
What will happen if I say delete this
Difference between “C structure” and “C++ structure”.
Diffrence between a “assignment operator” and a “copy constructor”
What is the difference between “overloading” and “overridding”?
Explain the need for “Virtual Destructor”.
Read all interview questions
Microsoft college recruitment questions
C++ Windows
Reader Vinay Solanki faced these questions from Microsoft recruiter, who apparently was hiring straight out of college.
How did you first get interested in Computer Science?
What do you like to do best related to computers now (programming, administration, testing, manage projects, etc)? What is it about that area that you specifically enjoy?
What is your strongest programming language (Java, ASP, C, C++, VB, HTML,C#, etc.)?
When is the last time you coded in C/C++? What is the most lines of original C/C++ code you have personally written in one project? How confident are you in your ability to write C or C++ without a reference?
Read all interview questions
Windows programming interview questions
What are kernel objects? - - Several types of kernel objects, such as access token objects, event objects, file objects, file-mapping objects, I/O completion port objects, job objects, mailslot objects, mutex objects, pipe objects, process objects, semaphore objects, thread objects, and waitable timer objects.
What is a kernel object? - Each kernel object is simply a memory block allocated by the kernel and is accessible only by the kernel. This memory block is a data structure whose members maintain information about the object. Some members (security descriptor, usage count, and so on) are the same across all object types, but most are specific to a particular object type. For example, a process object has a process ID, a base priority, and an exit code, whereas a file object has a byte offset, a sharing mode, and an open mode.

