LearnFrenzy
Sign in Take a free test

Typedef · Predict the Output · Question 6

const String: writing the characters is allowed Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

What is the output of the following C program on a 64-bit system?

main.c
#include <stdio.h>

typedef char *String;

int main(void) {
    char word[] = "abc";
    const String s = word;
    s[1] = 'B';
    printf("%s\n", s);
    return 0;
}
  • A aBc Correct
  • B abc
  • C Compilation error: s is const
  • D Bbc
Correct Answer: Option A

const String s is char *const s: the pointer is fixed, but the characters it points to are modifiable. Re-pointing s (s = other;) would be the compile error.

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.

Search LearnFrenzy

Esc

Quick links