How to pass a array to a function without having to report how many indexes it has?
Reporting the size
#include "stdafx.h"
#include <Windows.h>
void imprimir(int _array[], int _tamanho) {
for (int i = 0; i < _tamanho; i++) {
printf("%d\n", _array[i]);
}
}
int main()
{
int myArray[] = { 1, 2, 3, 4, 5 };
imprimir(myArray, 5);
getchar();
return 0;
}
Without the size
#include "stdafx.h"
#include <Windows.h>
void imprimir(int _array[]) {
// Aqui ele deve ser capaz de descobrir sozinho o tamanho da array.
int tamanho = _array[].tamanho; // Apenas uma abstração.
for (int i = 0; i < tamanho ; i++) {
printf("%d\n", _array[i]);
}
}
int main()
{
int myArray[] = { 1, 2, 3, 4, 5 };
imprimir(myArray);
getchar();
return 0;
}
I would like to give intelligence to my program so that it is able to figure out the size of the array by itself without having to pass it as a parameter.