Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program if the array begins 1200 in memory?

#include <stdio.h>

int main()
{
    int arr[]={2, 3, 4, 1, 6};
    printf("%u, %u, %u\n", arr, &arr[0], &arr);
    return 0;
}

 

  • A.1200, 1202, 1204
  • B.1200, 1200, 1200
  • C.1200, 1204, 1208
  • D.1200, 1202, 1200

Answer: B

Correct answer: 1200, 1200, 1200

All three expressions denote the same address, the start of the array: arr decays to &arr[0], &arr[0] is that address written out, and &arr is the address of the whole array, which begins at the same byte. Only their types differ, so all three print 1200.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.