Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
There is compilation error in my code
_array bound is not an integer constant before']' token
_ARRAY bound is not an integer constant before ']' token

What I have tried:

C++
#include<iostream>
using namespace std;

int n;

int _array[n];
int _ARRAY[n-1];
swap(int *i,int *k)
{int j;// js any temperory element
    j=*i;
    *i=*k;
    *k=j;
}
void sort(int _array[],int n )
{int hole;
    int i;
    hole = i;
    for(int hole=1;hole<n;hole++)>
    {
        if( hole>0 && _array[hole-1]>_array[hole])
        {swap(_array[hole],_array[hole-1]);
            hole=hole-1;
        }
}
}
int Findmindifference(){
int _array[n];
int _ARRAY[n-1];
 sort(_array,n);
for(int i=0;i<n-1;i++)>
{
    _ARRAY[i]=_array[i+1]-_array[i];
}
    sort (_ARRAY,n-1);

return _ARRAY[0];
}

int main()
{
    int t;
    cin >> t;
    for(int i=0;i<t;i++)>
    {
        cin >> n;

        for(int j=0;j<n;j++)>
        {
            cin >>_array[j];
        }
    }
        cout << Findmindifference();
}</iostream>
Posted
Updated 23-Jun-16 21:24pm
v3

1 solution

for the declaration of an array in that way you MUST specify a constant number.
C++
const int n = XXX; //your count goes here
 
int _array[n];
int _ARRAY[n-1];

alternativly the dynamic allocation:
C++
int *_array = 0;//declare a pointer to int (can be used for array

//in some function
_array = new int[n];//n can be variant

//at the end: cleanup
delete _array;

Some fine tutorial for that task.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900