You are viewing a single comment's thread. Return to all comments →
wow. thats pretty smart can you tell me where you learned it or walk me through your though proccess for
int *A = new int[N];
thats for dynamically allocating memory ie it adjusts its size according to the input during runtime
how different is it from the "malloc"?
malloc() is a function in C, and New is for C++
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!.
if you guys want to start your own business. But don't have money to start your business.
you can start your business at a very low investment, by joining a multi level marketing company .if your want to know how to choose a rught company then click here it is a business which is easy to start and run with very low risk.
Multi Level Marketing orMLM,
what does it mean. well it may surprise you but it is something that you already do every day, Multi Level Marketing simply means word-of-mouth advertising,or recommending something to someone. If you take a moment to think about it this is something that we all do on a regular basis, we refer friends to our favorite restaurants, movies and vacation spots.We refer books stores, doctors and any number of products that we like to people we know it's simply part of our nature.So the fact is we are all technically Multi Level Marketer,it's just who we are the difference is most of us don't get paid to do this.But some people do and they get paid very well.As you will learn in a moment they are compensated for far more than just their personal recommendations. for more info click here.
https://www.networkingmarketingnew.com/">9 tips for multi level marketing
In multi level marketing, many people come to earn money. Many people fall into this temptation, they will get a lot of money from here, they will not have to work here at all. You guys, let me tell you that without working here, you cannot earn money anywhere. Friends, let me tell you that
multi level marketing is a business that is exactly like a mountain.
If you want to dig it with a spoon, you will not be able to dig it all, nor will you be able to get it yourself with the help of ax. You will need JCB to find it. Similarly, in multi-level marketing too, you should get lots of tips and tricks, with the help of which you can dig the mountain or multi-level marketing.
If you work properly in multi-level marketing and keep developing your skills, then you will be able to earn a lot of money from here, but if you keep thinking in multi-level marketing, nothing has been done, and many more You get all the money here, you will waste your time here and you will not be able to earn anything. You have a lot of work here. Now work in the film part time, but for how long you are working, you will have to work with your mind.
In multi level marketing, there are some steps which are very important. You have to follow them everyday so that you can go far ahead in multi level marketing. In this post, I will tell you about the steps by doing them completely.You keep reading click here
Dude you write this in every problem's discussion , LOL i was just curious why you chose C++ forum for promotion , anyways get banned :&
here is Array Introduction problem solution in c++
One more difference is tha malloc and free just allocate memory to object, but new and delete apart from allocating memory also call constructor and destructor.
what is it mean by *A=new int[N]? why new keyword used? and what will happen by this expression?
not sure why people just downvote an honest question instead of responding with an answer - everyone is here to learn.
"As a rule of thumb, C++ pointers should only refer to objects allocated wth new."
you can read here for more explanation:
Section A3.8. Pointers
So basically, the 'new' operator will return a address (what a pointer stores) to the heap-allocated contiguous memory block, a.k.a. 'array' of ints, thus ".... new int[n]", where n = 10 would return the beginning address of the contiguous memory block(s).
(which in total would usually be 10 * 4 bytes(sizeof(int)) )
The reason you would use a heap-allocated block of contiguous memory a.k.a. 'array', is because you do NOT know the exact number representing the size of the array at COMPILE TIME.
So basically std::cin >> n; int* A = new int[n]; -> here 'n' will be known at RUNTIME, when the user interacts with the program and enters some number.
BUT! Performing calculations also based on non-const/already known values and using the result as the array size will not work either...
Depending on the compiler, but in GCC using g++, try doing all this with a stack allocated array - it MIGHT let you, and then try it with the -pedantic-errors flag and the compiler WON'T let you do such stuff...
std::cin >> n; int* A = new int[n];
So basically when you DO NOT KNOW the size of an array beforehand (like a hard-coded value '10' for example, or a const int or so) - use heap-allocated arrays!
that's the standard dynamic array implementation
new is for dynamic memory allocations. It create namless variables stored in the heap. He created a nameless array that can change size in runtime. Unlike normal array, N doens't need to be constant. The variables stored in the stack are destroyed once the program reach the end of their scope, while the heap variables don't. Therefore, they need to be explicitly delited to free memory. That's why he put delete a; at the end.