This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

array size

int a[x];

where x=0,1,2,3,.....n;

1.....in CCS compiler "x" should be a fixed length or MACRO.

2.....Is any other possible way to declare array size?

Thanks and Regards,

saitech.

  • Hello sridharan,

    C language requires the array size be a constant. What are you trying to do?

    You could compile your code as c++ and do something like the following:

    int x;
    x = 5;
    int * a;

    a = new int[x];

    a[0] = 1;
    a[1] = 3;
    // and ect.

    delete[] a;



    Stephen

  • Or if you'd like to use plain C:

    int x;
    x = 5;
    int * a;
    
    a = malloc(x * sizeof *a);
    
    a[0] = 1;
    a[1] = 3;
    // and ect.
    
    free(a);

    actually, if you use C++, try to avoid plain new/delete. Use a wrapper class.