I cannot seem to compile my code when initializing a variable-sized array (code below). The thing is the code below is a sample code from university lecture notes, so it should work perfectly fine but it doesn't.
int MAX = 20;
char input[MAX] = {'\0'};
I saw a question with similar title and the person stated that he can only compile when he use constant variable as the size of array. So I tried writing the code below but i still get the same compile error.
const int MAX = 20;
int main() {
char input[MAX] = {'\0'};
What's more confusing is that when i try to hard-code the size of the array (code below) it works. I don't understand why and what is the problem with the codes above when to me it looks the same with the code below.
char input[20] = {'\0'};
Is it a problem with the compiler? Or is this syntax not really allowed in C?
mallocfor this purpose. Otherwise, choose another language - Python, Ruby, etc.