Delete (C++)

Delete (C++)

In the C++ programming language, the delete operator returns memory allocated by new back to the heap. A call to delete must be made for every call to new to avoid a memory leak. After calling delete the memory object pointed to is invalid and should no longer be used. Many programmers assign NULL to pointers after using delete to help minimize programming errors. Note, however, that deleting a NULL pointer has no effect, so it is not necessary to check for NULL before calling delete.

Example code snippet:int *p_var = NULL; // new pointer declaredp_var = new int; // memory dynamically allocated /* .......other code........*/

delete p_var; // memory freed upp_var = NULL; // pointer changed to NULLArrays allocated with new [] can be similarly deallocated with delete [] :int size = 10;int *p_var = NULL; // new pointer declaredp_var = new int [size] ;// memory dynamically allocated

/* .......other code........*/

delete [] p_var; // memory freed upp_var = NULL; // pointer changed to NULL

Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Delete (C++) — В языке программирования C++ оператор delete возвращает память, выделенную оператором new, обратно в кучу. Вызов delete должен происходить для каждого вызова new, дабы избежать утечки памяти. После вызова delete объект, указывающий на этот… …   Википедия

  • delete — de‧lete [dɪˈliːt] verb [transitive] 1. to remove something written on a list, in a document etc: • Libelous remarks about living people have been deleted from the document. • The company will be deleted from the S & P 500 Index. 2. COMPUTING to… …   Financial and business terms

  • DELETE — DELETE  в языках, подобных SQL, DML операция удаления записей из таблицы. Критерий отбора записей для удаления определяется выражением where. В случае, если критерий отбора не определён, выполняется удаление всех записей. В СУБД,… …   Википедия

  • Delete — Delete: Delete оператор языка программирования C++. Delete операция в языках, подобных SQL. Delete клавиша на клавиатуре компьютера …   Википедия

  • Delete — De*lete , v. t. [imp. & p. p. {Deleted}; p. pr. & vb. n. {Deleting}.] [L. deletus, p. p. of delere to destroy. Cf. 1st {Dele}.] To blot out; to erase; to expunge; to dele; to omit. [1913 Webster] I have, therefore, . . . inserted eleven stanzas… …   The Collaborative International Dictionary of English

  • delete — I verb blot out, cancel, censor, cross off, cross out, cut, cut out, dele, discard, do away with, drop, edit out, efface, elide, eliminate, eradicate, erase, excise, expel, expunge, extirpate, get rid of, leave out, modify by excisions,… …   Law dictionary

  • delete — (v.) late 15c., destroy, eradicate, from L. deletus, pp. of delere destroy, blot out, efface, from delevi, originally perf. tense of delinere to daub, erase by smudging (as of the wax on a writing table), from de from, away (see DE (Cf. de )) +… …   Etymology dictionary

  • delete — (izg. dilȋt) m DEFINICIJA inform. tipka na tipkovnici koja služi za brisanje znaka na kojem se nalazi kursor, usp. backspace ETIMOLOGIJA engl.: brisati …   Hrvatski jezični portal

  • delete — cancel, efface, obliterate, blot out, expunge, *erase Analogous words: eliminate, *exclude, rule out: omit (see NEGLECT vb) …   New Dictionary of Synonyms

  • delete — [v] erase, remove annul, black out, bleep, blot out, blue pencil*, cancel, clean, clean up, cross out, cut, cut out, decontaminate, destroy, drop, edit, efface, eliminate, exclude, expunge, obliterate, omit, pass up, rub, rub out, rule out,… …   New thesaurus

  • delete — ► VERB ▪ remove or erase (text). DERIVATIVES deletion noun. ORIGIN Latin delere to blot out …   English terms dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”