C++ getting the size of an array -
I'm new to programming and I was wondering how to get an array size, which gets the size How many elements are inside the array, for example if I declare an array of size 10, but only 3 input elements in the array, how do I set the size of this array? If I do not know how many elements I had initially placed in
If you declare an array, e.g. You should consider using container classes, e.g. int array [10] , then its size is always
10 * size (int) . There is no way to know how many times you have accessed it; You need to keep track of yourself.
std :: vector :
std :: vector & lt; Int & gt; Vec; Vec.push_back (5); Vec.push_back (10); Vec.push_back (42); Std :: cout & lt; & Lt; Vec.size () & lt; & Lt; "\ N"; // print "3"
Comments
Post a Comment