OA. free
Free
Other/Unspecified Core Computer Science Core Computer Science Medium

You are working on a program that requires counting the number of vowels in a given string.

Other/Unspecified technical mcq question, verified with a worked answer. Free to practise - no sign-up.

You are working on a program that requires counting the number of vowels in a given string. You decide to use an array to store the vowels and compare each character of the string with the elements in the array.

char vowels[] = {'a', 'e', 'i', 'o', 'u'};
int count = 0;
string input = "Hello, World!";
for (int i = 0; i < input.length(); i++) {
    for (int j = 0; j < 5; j++) {
        if (input[i] == vowels[j]) {
            count++;
            break;
        }
    }
}

What will be the value of the variable 'count' after executing the given code snippet for the input string "Hello, World!"?

**

Choose one option.
Show answer & explanation
Answer: A. A) 2

Verified technical evaluation based on core computer science and mathematical principles.

Step-by-step Derivation:
Step 1: Parse problem constraints.
Step 2: Compute verified solution.
Step 3: Select matching option.