1

To initialize an array partially, below 2 initializers look similar. Is there some difference under some condition? I assumed the first syntax would initialize all elements in the array as 1, but it is proved not to be the case.

int arr[2] = {1,};
int arr[2] = {1};

Another thought is the extra comma adds extra element to the array, like array size is 2 below. But this is also not the case.

int arr[] = {1,}; // sizeof(arr) / sizeof(int) is 1 instead of 2

I am wondering is there any specific usage of the extra comma in the above initializer.

Magnus Hoff
  • 21,529
  • 9
  • 63
  • 82
Thomson
  • 20,586
  • 28
  • 90
  • 134
  • Explore before you ask: http://stackoverflow.com/questions/18160469/what-is-the-significance-of-comma-in-array-and-structure-initialization and http://stackoverflow.com/questions/7043372/int-a-1-2-weird-comma-allowed-any-particular-reason – Igor Pejic Sep 18 '14 at 08:15

0 Answers0