I realized that sizeof(arr)/sizeof(arr[0]) returns the size of the array and not the actual number of elements in the array.
int main(void)
{
int a = 1;
int b = 2;
int arr[5] = {a, b};
int arrcount = sizeof(arr)/sizeof(arr[0]);
printf("Array Size: %d\n", arrcount);
return EXIT_SUCCESS;
}
arrcount here equals to 5. Is there a way to get the number of elements equal 2 in this scenario without changing the array size?
1 2 0 0 0. The 0s still exist.std::vector.int arr[5] = {a, b};just remove the5here. It is not required when you're assigning to an array literal.static_vector?