LearnFrenzy
Sign in Take a free test

Pointers · Predict the Output · Question 9

Output of moving a char pointer through a string in C Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    char s[] = "LearnFrenzy";
    char *p = s;
    p += 5;
    printf("%s %c\n", p, *(s + 1));
    return 0;
}
  • A Frenzy e Correct
  • B LearnFrenzy L
  • C nFrenzy e
  • D Frenzy L
Correct Answer: Option A

After p += 5, p points to the 6th character, so %s prints from there: "Frenzy". *(s + 1) is s[1], the character 'e'.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Popular