📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Complete the C function to find the first occurrence of

    a character c in a string str and return its index. Return -1 if not found. #include // For strlen, though not strictly needed for this loop int find_char_index(const char* str, char c) {     int i = 0;     while (str[i] != '\0') {         if (_________ ) { // Line to complete             return i;         }         i++;     }     return -1; }
    A str[i] == c Correct Answer Incorrect Answer
    B str[i] != c Correct Answer Incorrect Answer
    C c == str[i] Correct Answer Incorrect Answer
    D str[i] == '\0' Correct Answer Incorrect Answer
    E i == c Correct Answer Incorrect Answer

    Solution

    Correct Answer: A (Or C, they are equivalent. But A is more conventional.)

    Practice Next
    ask-question