Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
irene3099764dOne word: constant.
In the second case compiler can produce one and only definition but in the first case it cannot because N is not a constant and cannot be calculated at compile time.
fuckwit89364dIn C array sizes have to be constant for the compiler to know how big that array is. try to put a 'const' before your variable that defines the size.
hashr116264dyou can use const keyword to define variable 'n'.
const int n = 100;
initializing const variable is compulsary
Voxera651064dIf you cannot use const you could fake it by defining the function as one dimensional and calculating the index by multiplying the first dimension by n and adding the second.
Its not very elegant code but it works.
The underlying problem is that thats basically what the compiler converts your code to, but without const as mentioned, the compiler does not know how long it should jump to reach the next row. So you have to do the calculation manually.
Your Job Suck?
Take a quick quiz from Triplebyte to skip the job search hassles and jump to final interviews at hot tech firms
Get a Better Job