Pointer to pointer malloc and manipulation?

With char *p2 you allocate 2 char on the stack. When accessing p2 you have a buffer overflow and might access any other fings belonging to the stack frame of the current method (some compilers check this in debug mode).

P is declared to have two elements, so p2 does not exist - hence the segfault. Since p is a local array (of pointers), sizeof(p) gives the size of the element type (and the element type is char *, whose size is 4) multiplied by the number of elements (2). Pp, on the other hand, is a pointer (to a pointer), not an array, so sizeof(p) is simply the size of a char **, which is the same as the size of any other pointer on a 32-bit machine, namely 4.

That the assignment to pp2 seems to succeed is pure chance - you're writing outside the allocated memory (which only contains space for two char * elements).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions