ProgrammingHardWipro · Cognizant pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
int countOccurrences(const char *str, char target) {
    int count = 0;
    while (*str) {
        if (*str == target) count++;
        str++;
    }
    return count;
}
int main(void) {
    printf("%d", countOccurrences("mississippi", 's'));
}
  1. A. 0
  2. B. 4
  3. C. 2
  4. D. 3

Correct answer: B. 4

"mississippi" contains the letter 's' four times (positions 2,3,5,6: m-i-s-s-i-s-s-i-p-p-i), so the loop counts 4.

More C Programming questions

Exams that ask this topic