Borland C ++ Builder Environment - Console App

int main() { int* i, *n, *idx; printf("Enter n: "); scanf("%d", &n); int** A = new int* [*n]; for (*i = 0; *i < *n; *i++) { A[*i] = new int [*n]; } A[3][3] = 100; printf("%d", A[3][3]); for (*i = 0; *i < *n; *i++) delete[] A[*i]; delete[] A; } 

After entering the dimension, the program is no longer executed. It does not generate errors, it simply does not run any further.

  • one
    great code))) - Gorets
  • one
    (I will try to ask a few suggestive questions) - You set up the "asterisks so that the compiler does not swear," right? :) - What semantics have expressions like int *i and &a ? How to determine the type of expression &a , if you know the original type of a ? - What value will the variable int a; right after its initialization? What will be the answer to the last question, if we are talking about the expression int *a; ? - Costantino Rupert
  • An asterisk missed in front of the square bracket you have to put it. So she tries to allocate from the hip the amount of memory equal to what lies at the address equal to n for one iteration of the cycle. Damn, while I wrote the answer, a dozen more asterisks hovered, mc is obviously confused in the editor, duplicate to escape metacharacters - igumnov
  • one
    Still, to represent the matrix in the form of a two-dimensional dynamic array is a bad idea. Use a one-dimensional array in a stack. To translate an index into ij, use a hash table if you want to work with large dimensions. - igumnov
  • one
    I agree with the distinguished @Gorets. But why is this code especially good? And the fact that there in the set of stars the Big Dipper is easily distinguishable and, accordingly, the direction to the north, where the long-awaited RETURN should be located. - BuilderC

1 answer 1

@ delphist007 Array declarators

There is no need for an expression; it is estimated that each time it is evaluated is not greater than zero. The size of each type does not change during its lifetime. It is unsure of the size of the operator.

  • Cool. And I standard on C99 to look was too lazy. - alexlz