C++ Datastructures and Algorithms Final Exam Solutions
- Assume the following variable declarations:
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++…