+ 3

How to know size of array in c++?

if i don't know how many values is to put in array by user how can i make array suppose i make array a[5] but only 3 values is to put

24th Dec 2017, 7:39 AM
Frankestine Stine
Frankestine Stine - avatar
3 Answers
+ 7
you can use dynamic arrays or vectors int *m, n; cin >> n; m = new int [n]; ... ...
24th Dec 2017, 8:50 AM
Botol
Botol - avatar
+ 4
You can do what @01ejka said, or alternatively: int a[] = {}; //Enter array cout << sizeof(a)/sizeof(int); Which will return the size of array.
24th Dec 2017, 9:00 AM
blackcat1111
blackcat1111 - avatar
- 1
You can also use a vector. The size of vectors is mutable.
24th Dec 2017, 1:35 PM
Timon Paßlick