I need the function PrintArray( int array[], int size); You can also print with the name of the array currently the function returns the string name configured in printf(); but that remains constant with array[X] We want that if we call the function For example PrintArray( int prices[], 5); Can print with the prefix prices[0], prices[1],
#include<stdio.h>
void ImprimirArray( int array[], int size);
int main(){
int precios[5]={10,20,30,40,50};
ImprimirArray( precios, 5);
return 0;
}
void ImprimirArray( int array[], int size){
int i;
for (i=0;i<size;i++) {
printf("array[%d]=%d\n",i,array[i]);
}
}
Short answer: You can't .
C does not have any kind of introspection information; it doesn't even store the size of your array , much less the name used for a variable.
Simple answer: Why don't you pass the name to the function?