Category Archives: C++

C++: some simple pointer arithmetic

What will be the output of the following code: Correct answer is: 1001 2002 3004 Because of the following table: char : 1 byte short : 2 bytes int : 4 bytes long : 4 bytes float : 4 bytes … Continue reading

Posted in C++, Interview, Programming | Tagged , , | Leave a comment

Things I was never aware of: C++. Comma operator.

In C++ comma “,” can be used in two ways. First, as an operator: expression1,expression2 Evaluation is from left to right. Expression on the left is evaluated first. Expression on the right is evaluated second giving the result of the … Continue reading

Posted in C++, Interview, Programming | Tagged , , | Leave a comment

Binary Search Trees

Binary search tree is one of the most often used data structure in computer science. It seems that computer science people like asking about BST and its algorithms in job interviews. The following are advantages of binary search trees (summarized … Continue reading

Posted in C++, Interview, Programming | Leave a comment

Reversing linked list

Posted in C++, Interview | Tagged , | Leave a comment

Useful idioms for C/C++ programming

To double integer n: To divide by 2 as integer: To check if n is even integer: Idioms below are due to Adam Peterson. Instead of better: sizeof *telegram is computed at compile time! Size of array by division: NUM_OF_HANDLES … Continue reading

Posted in C++, Productivity, Programming | Tagged , , , , | Leave a comment

Operator precedence: what happens when statement *a++ is executed?

Consider a function that copies content of array a into array v: Statement *a++, according to C/C++ operator precedence table, is interpreted as: so that the pointer is incremented before de-referencing. However, since we have a post-increment operator here (pre-increment … Continue reading

Posted in C++, Programming | Tagged | Leave a comment

How to create a simple C++ Makefile

Remember to use “Tab” as a separator. Set the name of the final binary file for the program. TARGET = test_functions $(TARGET) is the way to dereference the content of the variable. Set compiler flags for #include directories so that … Continue reading

Posted in C++, Programming | Tagged | Leave a comment