0

Does int a[]{}; is a empty array?

26th May 2018, 4:22 AM
RainStorm
RainStorm - avatar
5 Answers
+ 20
if you mean int a[]={}; answer is yes
26th May 2018, 4:24 AM
AliRà«Żza
AliRà«Żza - avatar
+ 4
int a[]{}; initializes an array a of size 0 storing no elements. Note that this is list initialization, which is a valid syntax for for initializing arrays, e.g. int arr[] = {1,2,3}; int arr2[]{1,2,3}; http://en.cppreference.com/w/cpp/language/list_initialization#Explanation
26th May 2018, 4:54 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Martin Taylor Ah, thanks. I've just read an article on how list initialization may be useful, though. Turns out it might not just be a shorthand, but I may be wrong. Of course, conflicting views are also present. Thoughts? https://stackoverflow.com/questions/18222926/why-is-list-initialization-using-curly-braces-better-than-the-alternatives
26th May 2018, 9:26 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
The array needs to be declared first. Try: int [] a = new int[10]; This array will be declared as an array capable of storing up to 10 elements.
26th May 2018, 4:31 AM
Danny