error in line 23 i.e a constant value

in line 23.
int a[n];
give error while running i.e. expression must have a constant value.
so, rectifying this we can use pointer.
int* a = new int[n];
This commit is contained in:
Faizan Ahamed
2020-04-26 14:18:01 +05:30
committed by GitHub
parent 41319636c1
commit 5dbd45a3f0

View File

@@ -20,7 +20,13 @@ int main(int argc, char const *argv[])
cout << "Enter size of array: ";
cin >> n;
cout << "Enter array elements: ";
/*
int a[n];
getting error size must be declare
so for rectifying this use pointer.
int a[n]; replace by int* a = new int[n];
*/
int* a = new int[n];
for (int i = 0; i < n; ++i)
{
cin >> a[i];
@@ -33,4 +39,4 @@ int main(int argc, char const *argv[])
else
cout << key << " not found" << endl;
return 0;
}
}