I want to pass the B int array pointer into func function and be able to change it from there and then view the changes in main function
#include <stdio.h> int func(int *B[10]){ } int main(void){ int *B[10]; func(&B); return 0; } the above code gives me some errors:
In function 'main':| warning: passing argument 1 of 'func' from incompatible pointer type [enabled by default]| note: expected 'int **' but argument is of type 'int * (*)[10]'| EDIT: new code:
#include <stdio.h> int func(int *B){ *B[0] = 5; } int main(void){ int B[10] = {NULL}; printf("b[0] = %d\n\n", B[0]); func(B); printf("b[0] = %d\n\n", B[0]); return 0; } now i get these errors:
||In function 'func':| |4|error: invalid type argument of unary '*' (have 'int')| ||In function 'main':| |9|warning: initialization makes integer from pointer without a cast [enabled by default]| |9|warning: (near initialization for 'B[0]') [enabled by default]| ||=== Build finished: 1 errors, 2 warnings ===|
int *, butfuncexpects anint**(which is expected to be a pointer to the first element of an array of (10, presumably)int*s). How to fix it depends on whatfuncdoes.B. SinceBis actually an array, passing&Bis typically not useful, sinceBcan't be changed (but its contents can be changed, and that's what you want to do).funcshould be declared like this:int func(int (*B)[10])