17.05.2013 Views

Manual de lenguaje C++

Manual de lenguaje C++

Manual de lenguaje C++

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Asignación dinámica <strong>de</strong> memoria: new y <strong>de</strong>lete<br />

En C la asignación dinámica <strong>de</strong> memoria se manipula con las funciones malloc() y free(). En <strong>C++</strong> se<br />

<strong>de</strong>fine un método <strong>de</strong> hacer asignación dinámica utilizando los operadores new y <strong>de</strong>lete.<br />

En C:<br />

void main()<br />

{<br />

int *z;<br />

z= (int*) malloc(sizeof(int));<br />

*z=342;<br />

printf("%d\n",*z);<br />

free(z);<br />

}<br />

En <strong>C++</strong>:<br />

void main()<br />

{<br />

int *z=new int;<br />

*z=342;<br />

cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!