I was reading this post and the OP says that he was worried that "that appending A's allocated memory will corrupt the heap ", so he instead allocated new memory, memcopy A, and memset.
i was wondering if that is the case. is it not possible to append without allocating new memory.
I made a lame attempt. and i got an error
int a[3] = {14, 2, 7}; // initialize array
int M = 2;
int size = sizeof a / sizeof a[0]; // size of array
// print contents of array
for (int i=0;i<size;i++) {
printf("%d\n", a[i]);
}
// add (post pad) 2 zeros to existing array , a
memset(a+M, 0, M * sizeof(int));
int size2 = sizeof a / sizeof a[0];
printf("%d\n", size2);
// print updated array
for (int i=0;i<size2;i++) {
printf("%d\n", a[i]);
}
"*** stack smashing detected ***: terminated"