LearnFrenzy
Sign in Take a free test

Typedef · Predict the Output · Question 2

#define vs typedef for char pointers – sizes Answer, explanation & discussion

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

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

main.c
#include <stdio.h>

#define STR char *
typedef char *Str;

int main(void) {
    STR a, b;
    Str c, d;
    printf("%zu %zu %zu %zu\n", sizeof a, sizeof b, sizeof c, sizeof d);
    return 0;
}
  • A 8 1 8 8 Correct
  • B 8 8 8 8
  • C 1 1 8 8
  • D 8 1 8 1
Correct Answer: Option A

The macro expands to char * a, b;, so b is a single char (1 byte). The typedef makes both c and d pointers (8 bytes each).

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