C++ Datastructures and Algorithms Final Exam Solutions

int foo = 0;
int *ptr = &foo;

What statements will change the value of foo to 1?

(*ptr)++;foo++;

2. Write a function countMatches which compares 2 C strings and count the number of matching characters.

void countMatches(const char *str1, const char *str2, int &count) { 
int count = 0;
while (*str1 != '\0' &&*str2 != '\0') {
if (*str1 == *str2) {
count++;
}
str1++…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store