0

I can't seem to find anything regarding whether or not this is possible. Ideally I'd have someone input an integer like "4" and then it would make a 4-d array.

is this at all possible?

  • 2
    Yes, it is possible. What have you tried? – OldProgrammer Oct 26 '14 at 23:49
  • 2
    When you say a "4-d array" what do you actually mean? An array with 4 elements or something which is accessed as `array[n0][n1][n2][n3]`? While the former is possible, I don't think the latter is possible in C++. Other programming languages may allow a dynamic specification of dimensions. – Dietmar Kühl Oct 27 '14 at 00:00

1 Answers1

1

As explained in the Stack Overflow post, "Create an N dimensional array, where N is determined at runtime (C++)":

The dimensions of an array are part of the type, and the type must be known 
at compile time.

Thus the programmer must specify the dimensions of the array before compile-time, not during run-time.

Type checking is typically one of the first operations a compiler does (it is specifically found in the semantic analysis portion of the compiler's control flow) to ensure the code received is free of simple programming errors (assignment/equivilance errors, etc).

Please let me know if you have any questions!

Community
  • 1
  • 1
Devarsh Desai
  • 5,984
  • 3
  • 19
  • 21