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


    Question

    Consider the following C code: #include

    #include int main() {     char* text = "The quick brown fox jumps over the lazy dog.";     char* pattern = "fox";     char* result = strstr(text, pattern);     if (result != NULL) {         printf("%ld\n", result - text); // Print index     } else {         printf("-1\n");     }     return 0; } What will be the output of this program?
    A 16 Correct Answer Incorrect Answer
    B 17 Correct Answer Incorrect Answer
    C 18 Correct Answer Incorrect Answer
    D 19 Correct Answer Incorrect Answer
    E -1 Correct Answer Incorrect Answer

    Solution

    Correct Answer: A (Indices: T-0, h-1, e-2, ' '-3, q-4, u-5, i-6, c-7, k-8, ' '-9, b-10, r-11, o-12, w-13, n-14, ' '-15, f-16. So 'fox' starts at index 16.)

    Practice Next
    ask-question