I'm trying to pass an array of pointers to a function, without the need to define the size. Also the output is a warning "initialization makes pointer from integer without cast. Mostly interested in passing array of pointers rather than an array because I'm trying to understand how to deal with the instance when Data is a dynamically allocated memory using malloc
Why is this happening, and how can I pass an array of pointers as an argument, without the need to define its size?
Code:
#include <stdio.h>
void printData(int *data[]);
void main (int argc,char *argv[]){
int *Data[] = {4, 8, 15, 16, 23, 42};
printData(Data);
}
void printData(int *data[]){
int **cur_data = data;
int counter = sizeof(data)/sizeof(int);
for(int i = 0; i<counter; i++){
printf("%d. %d\n", i, *cur_data);
cur_data++;
}
}
Warning:
main.c: In function ‘main’:
main.c:9: warning: initialization makes pointer from integer without a cast
main.c:9: warning: initialization makes pointer from integer without a cast
main.c:9: warning: initialization makes pointer from integer without a cast
main.c:9: warning: initialization makes pointer from integer without a cast
main.c:9: warning: initialization makes pointer from integer without a cast
main.c:9: warning: initialization makes pointer from integer without a cast
gcc main.o -o run
Run:
0. 4