LearnFrenzy
Sign in Take a free test

Typedef · Predict the Output · Question 7

A local typedef hiding a global one – output Answer, explanation & discussion

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

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

main.c
#include <stdio.h>

typedef int Number;

int main(void) {
    printf("%zu ", sizeof(Number));
    {
        typedef double Number;
        printf("%zu ", sizeof(Number));
    }
    printf("%zu\n", sizeof(Number));
    return 0;
}
  • A 4 8 4 Correct
  • B 4 8 8
  • C 8 8 8
  • D Compilation error
Correct Answer: Option A

The inner typedef has block scope and hides the outer one only inside the braces. After the block, Number is int again.

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