LearnFrenzy
Sign in Take a free test

Arrays · Predict the Output · Question 8

sizeof of a 2D array, a row and an element Answer, explanation & discussion

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

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int m[4][5];
    printf("%zu %zu %zu\n", sizeof m, sizeof m[0], sizeof m[0][0]);
    return 0;
}
  • A 80 20 4 Correct
  • B 20 5 4
  • C 80 8 4
  • D 80 20 8
Correct Answer: Option A

The whole matrix is 4 × 5 × 4 = 80 bytes. m[0] is one row of 5 ints = 20 bytes (an array, not a pointer, under sizeof), and one element is 4 bytes.

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