LearnFrenzy
Sign in Take a free test

C Const · Predict the Output · Question 5

sizeof a const char pointer vs a const char array Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

What is the output on a 64-bit system?

main.c
#include <stdio.h>
#include <string.h>

int main(void) {
    const char *s = "const";
    const char t[] = "const";
    printf("%zu %zu %zu\n", sizeof s, sizeof t, strlen(s));
    return 0;
}
  • A 8 6 5 Correct
  • B 6 6 5
  • C 8 5 5
  • D 5 6 5
Correct Answer: Option A

s is a pointer (8 bytes); t is an array holding the 5 letters plus '\0' (6 bytes). const does not change any size; strlen counts 5 characters.

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