Silly question, but why does the following line compile?
int[] i = new int[] {1,};
As you can see, I haven't entered in the second element and left a comma there. Still compiles even though you would expect it not to.
On computers running Windows or MS-DOS, the hard drive is labeled with the drive letter C, because it is the first available drive letter for hard drives. The computer reserves the A: and B: drive letters for the floppy disk drive and removable media, such as tape drives,...
In the early version of C++ would let ‘this’ pointer to be changed; by doing so a programmer could change which object a method was working on. This feature was eventually removed, and now this in C++ is an r-value.
Why learning C Programming is a must? C is a procedural programming language. It was initially developed by Dennis Ritchie between 1969 and 1973. It was mainly developed as a system programming language to write operating system.
Why Not A Or B? Why Do Drives Start From C? The various logical drives in Windows are assigned a drive letter. Generally, the drive letter for the first logical drive is C followed by D, E, F. Well, A and B are also alphabets but Windows reserves these drive letters for some special purpose, which is floppy drives.
I suppose because the ECMA 334 standard say:
array-initializer:
{ variable-initializer-list(opt) }
{ variable-initializer-list , }
variable-initializer-list:
variable-initializer
variable-initializer-list , variable-initializer
variable-initializer:
expression
array-initializer
As you can see, the trailing comma is allowed:
{ variable-initializer-list , }
↑
P.S. for a good answer (even if this fact was already pointed by many users). :)
Trailing comma could be used to ease the implementation of automatic code generators (generators can avoid to test for last element in initializer, since it should be written without the trailing comma) and conditional array initialization with preprocessor directives.
This is syntax sugar. In particular, such record can be useful in code generation.
int[] i = new int[] {
1,
2,
3,
};
Also, when you are writing like this, to add new line you need to add text only in single line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With