// Frosty edit: Tam, kde je naps?no [i.] to m? b?t bez t? te?ky. Upravil jsem to tak, proto?e F?rum to form?tuje jako kurz?vu.
Mrkn?te se na tento k?d:
#include <cstdlib>
#include <iostream>
using namespace std;
char* allocate_mem(char* c, int size) {
char* a = new char[size];
for(int i = 0; i != size; i++)
a[i.] = c[i.];
return c;
};
int main(int argc, char *argv[])
{
char* pa = allocate_mem("abcdef", 6);
cout << "Adresa 'pa': " << &pa << endl;
char ca[10] = "abcdefghi";
char* da = allocate_mem(ca, 10);
cout << "Adresa 'da': " << &da << endl; //Vsimnete si rozdilu
cout << "Hodnota 'da':" << da << endl;
cout << "Adresa 'ca': " << &ca << endl;
cout << "Hodnota 'ca':" << ca << endl;
int ia[10];
cout << "Adresa 'ia': " << ia << endl; //ALE !!!
delete []pa;
delete []da;
char cdf[9] = "12345678";
cout << "[del] Adresa 'da': " << &da << endl;
cout << "[del] Hodnota 'da':" << da << endl;
cout << "[del] Adresa 'ca': " << &ca << endl;
cout << "[del] Hodnota 'ca':" << ca << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Jak je mo?n?, ?e po smaz?n? dynamycky alokovan?ch prom?nn?ch oper?torem delete lze s nimy i nad?le pracovat? Zkou?el jsem to kompilovat v MinGW - debugger nic nehl?sil, posl?ze v M$ kompil?toru - debugger mi akor?t navrhl p?eru?en? b?hu programu po oper?torech delete.