Q:

Find the count of elements in array in C++

I am trying to develop a C++ program. I am facing a problem. I have declared an array of length 100 as int arr[100].
But I have only filled 20 entries in it. Now I want to find the total number of elements in the array, which should be 20. How do I find the number of elements filled in the array? 
I have tried
int size= sizeOf(arr)/sizeof(int);

but this gives me 100. I only want to get the elements which I have allowed the user to enter. 
Actually, there is a situation where the number of generated outputs can be any number. So I assigned each value in a separate array as arr[]. Then I want a loop through the length of the array. 
How to calculate the total number of outputs I am getting in the array?

A:

Every time you work with fixed-size arrays for which you want to consider some positions empty and the others filled, you must keep track of the filled element count in a separate variable. Why? Because you always have 100 elements in your array - you created them. Only that you are not using some of them - and only you know that.
This is one of the many reasons why you should use std::vector.

