[ create a new paste ] login | about

Link: http://codepad.org/PsoxEgBb    [ raw code | output | fork ]

C++, pasted on Dec 11:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
int main()   {
char str1[]="hello world" ;
char* pStr2 = new char[(sizeof(str1)-1)];  // выделяем днамически массив длиной в строку №1
for (uint i=0; i< (sizeof(str1)-1); i++) //-1 потому что последний символ нуль-терминатор и массив нумеруется с 0
{
    pStr2[(sizeof(str1)-2-i)]=str1[i];//-2 из-за того, что последний символ нуль-терминатор т массив нумеруется с 0
}
pStr2[(sizeof(str1)-2+1)]=0x00; //заканчиваем строку нуль-терминатором

printf("%s\n",pStr2);
delete[] pStr2;      //освобождаем память
return 0;
}


Output:
1
2
3
memory clobbered past end of allocated block

Exited: ExitFailure 127


Create a new paste based on this one


Comments: