LearnFrenzy
Sign in Take a free test

Arrays · Predict the Output · Question 3

&a + 1 vs a + 1 – output in C Answer, explanation & discussion

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

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int a[6];
    printf("%td %td\n", (&a + 1) - &a, (char *) (&a + 1) - (char *) a);
    return 0;
}
  • A 6 6
  • B 1 6
  • C 24 24
  • D 1 24 Correct
Correct Answer: Option D

&a points to the whole array (int (*)[6]). Subtracting two such pointers counts whole arrays: 1. Measured in bytes (char *), the jump is the full array size: 6 × 4 = 24.

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