I have a Java background and am learning C++. I have a language implementation / syntax decision question.
In Java, array declaration looks like this:
//generally
type[] variableName;
//concretely
int[] intArray;
However, in C++, it looks like this:
//generally
type variableName[size];
//concretely
int intArray[5];
The Java version makes sense to me, that the brackets should append the datatype. The variable is not an int
, it's an int array, so we replace the int
with int[]
.
In C++, why are the brackets after the variable name?
(Further, C++ seems to agree with this when it comes to pointers. An int
pointer is int* intPtr
not int ptr*
. What am I missing?)