Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the following C code?

#include <stdio.h>
    int main()
    {
        char str[10] = "hello";
        char *p = strrchr(str, 'l');
        printf("%c\n", *(++p));
    }

 

  • A.l
  • B.o
  • C.e
  • D.Compilation error

Answer: B

Correct answer: o

strrchr finds the last 'l', which in hello is at index 3. The pre-increment moves the pointer on one, to index 4, and that character is o.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.