3 ms·
Not to be confused with: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int *x = malloc(sizeof(int) * 5); memset(x
by IgorPartola 15y ago
Not to be confused with:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int *x = malloc(sizeof(int) * 5);
memset(x, 0, sizeof(int) * 5);
printf("%d\n", *x);
printf("%d\n", *(x+1));
printf("%p\n", x);
printf("%p\n", x+1);
printf("%p\n", &x);
printf("%p\n", &x+1);
return 0;
}
- matthavener 15y agoOr, not to be confused with: #include <stdio.h> #include <stdlib.h> #include <string.h> void foo(int x[5]) { printf("%p\n", x); printf("%p\n", x+1); printf("%p\n", &x); printf("%p\n", &x+1); } int main() { int x[5]; foo(x); return 0; }
- bbq 15y agoTo be confused with: #include <stdio.h> void foo(int (*x)[5]) { printf("%p\n", *x); printf("%p\n", *x+1); printf("%p\n", x); printf("%p\n", x+1); } int main(void) { int x[5]; foo(&x); return 0; }
- teichman 15y agoCan you elaborate on this?
- matthavener 15y agoIn C, the array as a function parameter is different from an array as a variable/struct member. So, as a parameter, sizeof(x) is sizeof(int*). As a variable, sizeof(x) is sizeof(int[5]).