C and C++ code exercise