I recently came across some code in stackoverflow, where pointers to pointers, where used to change allocated memory. When checking the code, I made a mistake to add an ampersand to the pointer, so make a pointer to a pointer that is still compiled by the compiler, and runtime errors have occurred. As an example
#include <stdio.h>
void func(int **p) {
printf("Pointer is at %p\n", p);
}
int main(void) {
int *p = 0;
func(p);
func(&p);
int **pp = &p;
func(&pp);
return 0;
}
I understand that C has significantly lower restrictions for pointers than C ++, and allows something like char *buf = malloc(SIZE)that, although this is not allowed in C ++. I see this as a convenience because it happens in C.
, , , , , int int*. , , C.
.com, , , . clang, gcc, . , , .
PS, , SO - . , , .