New and Delete Operators in C++ | Dynamic Memory Allocation | CPP Programming Video Tutorial

preview_player
Показать описание
In this c++ / cpp programming video tutorials / lecture for beginners video series, you will learn about how to do dynamic memory allocation using new and delete operators.

check out what is dynamic memory allocation and what is the need of it at

you will learn how to use new and delete operators in c++, how they works, how to allocate memory using new and how to deallocate or free memory using free with examples.

Learn Programming in HINDI at our youtube channel

Catch us on SocialMedia
Рекомендации по теме
Комментарии
Автор

great tutorial. you can also just place paranthesis and put int value in them like here:

int *ptr;
ptr= new int(24);
cout<<*ptr<<endl;

instead of declaring *ptr=24;

TheticblogLive
Автор

i WILL DEFINITELY THANK YOU in MY GRADUATION COMPLETION SPEECH😜

TopCategory
Автор

i am from NIT you are teaching better than my professors

Official-tknc
Автор

Great.you made c++ easier for us. Thank you soo much!

nehabhaskar
Автор

Great explanation. Is it possible to find size of the reserved memory for a specific variable in heap? For stack, it is sizeof() but what would be the case for heap????

qaribullah
Автор

nice tutorial but I think these days where we have modern c++ you should mention shared_ptr/unique_ptr instead of new/delete. It should be clear for every new programmer that new/delete is very error prone!

MikeMitterer
Автор

You have been very helpful....thought I have subscibed :(. Doing it now. Keep up the great work

georgeallan
Автор

sir, will i be able to do 11th 12th class c++ programs after watching and understanding these 143 videos... thank u

ajstsubasa
Автор

great one mate!!
I am not a Computer Science student but love coding and sometimes I et these wierd doubts.
Instead of initialising your pointer(dynamic) with a value what would be the workflow when you initialize pointer to an variable address?
Everything is fine until you encounter delete where the original variable is also deleted and finally ends up with an error.
Just like copied code:
#include <iostream>
using namespace std;

int main ()
{
int a = 12;
int *p = new int;
p = &a;
*p = 1;
delete p;
return 0;
}

saideep
Автор

thanks bro that'sn easy whith you .

zaatriabdelhakim
Автор

please sir make a short project on the basis of your all lecture.

naveenkatiyar
Автор

whats the point of dynamically allocating the memory when the pointer only points toward a single variable(like the example you showed in the video)? i get it, when you want to declare an array not knowing the number of its elements its best to dynamically allocate the memory to just reserve the right amount of memory in the heap..

daniel
Автор

So if im making a real program and not just a C++ instructional program, should I always use new/delete when working with pointers?

bredmond
Автор

Why dynamic memory allocation is required for any program??

aniket
Автор

What do you mean with "programs". So you need to free the memory, so other "programs" can use that memory. But I can't really imagine what those other "programs" are? You mean different functions, or a piece of your codes?

CindyK
Автор

if we don't delete the pointer and give the *pointer a new value( say 56 then if we again print the *pointer we get our value (56)...then what's the need of deleting????

varshalalwani
Автор

new keyword can only be used to allocate memory dynamically to the pointers.

harshpalsingh
Автор

What does delete do? I understand that it means freeing the memory, but at the end of the program after calling delete, I tried printing *pointer and pointer again and the values are still the same (24 and a memory address). How do I validate that the delete operation is successful? Please assist.

reenamoore
Автор

Thanks!
Can someone tell me why I should use New and allocate heap memory, over just creating the object in the stack? Will I be able to access the object outside of the function scope if I do new?

simonolofsson
Автор

hello,
why I couldn't allocate in the heap memory an unsigned long int?
// p = new unsigned long int;

yosrimhamdi