Primary Why is processing a sorted array faster than an unsorted array? Here is a piece of Visual C++ code that seems very peculiar. For some strange reason, sorting the data miraculously makes the code almost six times faster. #include <algorithm> #include <ctime> #include <iostream> int main() { // Generate data const unsigned arraySize = 32768; int data[arraySize]...
Primary What is the difference between #include <filename> and #include “filename”? The difference is in the location where the preprocessor searches for the included file. For #include "filename" the preprocessor searches in the same directory as the file containing the directive. This method is normally used to include programmer-defined header files. For #include <filename> the preprocessor searches...
Primary What are the differences between a pointer variable and a reference variable? * A pointer can be re-assigned: int x = 5; int y = 6; int *p; p = &x; p = &y; *p = 10; assert(x == 5); assert(y == 10); A reference cannot, and must be assigned at initialization: int x = 5; int y = 6; int &r = x; * A pointer has its...
Primary What is the name of the "-->" operator? Here's an example: #include <stdio.h> int main() { int x = 10; while( x --> 0 ) // x goes to 0 { printf("%d ", x); } } Answer --> is not an operator. It is in fact two separate operators, -- and >. The conditional's...