C program Array as a parameter -
i write function like:
void func1(char chx[], int y) { int wsn = 0; wsn = *(int *) (&chx[2]); if (wsn == 0) { ... } }
compiler works well, no warning, no error. when code running, seems wild pointer. code crashed.
wonder why crashed
arrays, when passed functions, decays pointers. means in func1
variable chx
pointer, doing &chx
gives pointer pointer.
the solution: don't utilize address-of operator &
.
c
No comments:
Post a Comment