Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ım having problem with constant concept in c

int main()
{
    int num;
    printf("enter a number:");
    scanf_s("%d", &num);
    int array[num];//this line gives errors
    for (int i = 0; i < num; i++)
    {
        array[i] = 1 + rand() % 100;
        printf("%d ", array[i]);
    }
}

Hi everyone I am having a constant problem in my c practice.This code runs well in online compiler but when ı try to run it with vs ı am getting a constant value and expression problem ı am not familiar with.I am a new coder so any help is appriciated.Thanks allready.(ı added a screen shot too in case you need one)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Microsoft compiler still did not implement C99 features like VLAs or flexible arrays.

You cant use:

int array[num];

as Microsoft does not support it. num has to be constant expression.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading