I wrote this function to swap values in a multi-dimensional array with my understanding that arrays are pointers.
void
swap(int* a, int* b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
However when I try to use the function
swap(board[d-1][d-2]), board[d-1][d-33];
I get these errors from the compiler and I don't know why:
fifteen.c: in function 'init':
fifteen.c:166:9: error: passing argument 1 of 'swap' makes pointer from integer without a cast [-werror]
fifteen.c:45:6: note: expected 'int *' but argument is of type 'int'
fifteen.c:166:9: error: passing argument 2 of 'swap' makes pointer from integer without a cast [-werror]
fifteen.c:45:6: note: expected 'int *' but argument is of type 'int'
How do I fix it?
int64_t num = 1234;andmemcpy(buf, &num, sizeof(num))in this casenumbehaves as an array of 8 bytes. ex.:char text[] = "...";thenint32_t *ptr=(int32_t*)&text[0];and when youptr++;the content of*ptrwill be the next 4 bytes insidetext.sizeofs: liveworkspace.org/code/853fc936ff59eee2994ab28ca0c02e92