LearnFrenzy
Sign in Take a free test

Complicated Declarations · Predict the Output · Question 11

int (*(*get)(void))[3] in action Answer, explanation & discussion

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

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

main.c
#include <stdio.h>

static int data[3] = {7, 14, 21};

int (*fetch(void))[3] {
    return &data;
}

int main(void) {
    int (*(*get)(void))[3] = fetch;
    int (*arr)[3] = get();
    printf("%d %zu\n", (*arr)[2], sizeof *arr);
    return 0;
}
  • A 21 12 Correct
  • B 7 12
  • C 21 8
  • D 14 12
Correct Answer: Option A

fetch returns a pointer to an array of 3 int, and get is a pointer to such a function. Calling get() yields &data; (*arr)[2] is 21 and *arr is 12 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