I have a structure, say a struct ZKN. It contains charms / ints, it does not matter.
And I wanted to make 12 such structures. And then there was a strange glitch (maybe I just do not know what).
If after defining the structure, immediately write zkn [11], i.e.

struct ZKN { ... } zkn[11]; 

then everything works fine. But if I declare the designation, write ZKN zkn [11] in main ; the compiler is already AFTER program execution, while successful, will be cursing.
Is he swearing at the wrong memory allocation, or what? And why then immediately after the structure, if we declare, then the norms, and in the main, not the norms.
Plus, in a book on C ++, they declare that in main, that right after the structure, they don’t care. How so?

    1 answer 1

    The book correctly states that you can declare a variable zkn anywhere. Only you need to do it right, if you need 12 structures, then why declare them 11?

    It should be:

     ZKN zkn[12]; 

    And the error is most likely associated with going beyond the array, if you are viewing the 12 elements of the array, in which there are only 11.

    • Well, because 0-11, no? - DizzWebS
    • And in that case - why does it normally determine everything, if immediately after the structure write zkn [11]? - DizzWebS
    • one
      Everything is correct, the index is from 0 to 11, but you need to declare an array not specifying the last index, but the number of elements in it. Going beyond the array is not predictable, now everything is fine, after 5 minutes there isn’t. - IAZ