c - passing argument 1 of 'recievematrix' from incompatible pointer type -


#include<stdio.h>  funtions prototypes int functiondouble(int b); void notreturnanything(int a, int b); void byreference(int *b); void receivevector(int v[]); void recievematrix(int m[][1]);  int main() {     int c;     printf("%d\n",functiondouble(5));     notreturnanything(3,9);     c = 0;     byreference(&c);     printf("%d\n",c);     int a[10], b[3][4];     receivevector(a);     recievematrix((int)b); // <----- warning: passing argument 1 of 'recievematrix' incompatible pointer type [enabled default]|     return 0; }  int functiondouble(int b) {     int a;     = 2*b;     return a; }  void notreturnanything(int a, int b) {     printf("%d\n",a+b); } 

is ok. 2 funtion no problems. receive single value without problems.

void byreference(int *b) {     *b = 7; }  void receivevector(int v[]) {     scanf("%d", &v[0]); }  void recievematrix(int m[][1]) {     scanf("%d", &m[1][1]); } 

this prove see how work arrays in c, pulls mistake , not error.

this ...

int b[3][4]; 

... declares array of 3 arrays of 4 ints. given declaration, in expressions array name b converted pointer first element; is, pointer array of 4 ints (int (*)[4]);

this ...

int m[][1] 

... declares array of unspecified number of arrays of 1 int. in argument list of function, converted pointer array of 1 int (int (*)[1]).

int (*)[4] not compatible int (*)[1]. resolve warning (which should do) without changing type of variable b, change signature of receivematrix() to

void recievematrix(int m[][4]); 

or

void recievematrix(int (*m)[4]); 

or even

void recievematrix(int m[3][4]); 

for matter, even

void recievematrix(int m[17][4]); 

would silence warning, though wouldn't recommend using it.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -