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

Discussion

What will be the output of the program if the array begins at address 65486?

#include <stdio.h>

int main()
{
    int arr[] = {12, 14, 15, 23, 45};
    printf("%u, %u\n", arr, &arr);
    return 0;
}

 

  • A.65486, 65488
  • B.65486, 65486
  • C.65486, 65490
  • D.65486, 65487

Answer: B

Correct answer: 65486, 65486

arr decays to a pointer to its first element and &arr is a pointer to the whole array. Both start at the same place, so both print 65486. They differ only in type, which shows up when you add to them: arr+1 moves by one int, &arr+1 by the whole array.

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

Post your comment

Please log in or register to post a comment.