LearnFrenzy
Sign in Take a free test

Typedef · Predict the Output · Question 9

typedef of a function type (not a pointer) – output Answer, explanation & discussion

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

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

main.c
#include <stdio.h>

typedef int Transform(int);

static int negate(int x) { return -x; }

int main(void) {
    Transform *t = negate;
    printf("%d %zu\n", t(7), sizeof(Transform *));
    return 0;
}
  • A -7 8 Correct
  • B -7 4
  • C 7 8
  • D Compilation error
Correct Answer: Option A

Transform names a function type, so Transform * is a pointer to such a function (8 bytes). This style keeps the * visible at the point of use, which some codebases prefer.

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