Difference Between Creating Variables in Stack and Creating them in Heap, and Using Pointers in General | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference Between Creating Variables in Stack and Creating them in Heap, and Using Pointers in General

What is the difference and comparison between creating variables in the stack and creating variables in the heap? Also, what are the benefits of using pointers or not? Example: int i = 5; - VS - int ipval = 5; int *ip = &ipval; - VS - int ipval = 5; int *ip = new int; *ip = ipval;

16th Jul 2017, 1:44 AM
Alex Fanat
Alex Fanat - avatar
4 Answers
+ 1
2nd & 3rd can give you address of ipval
16th Jul 2017, 2:51 AM
‎ ‏‏‎Anonymous Guy
+ 1
I know, but are there any functional differences? As in, is it faster or safer to use one or the other?
16th Jul 2017, 3:19 AM
Alex Fanat
Alex Fanat - avatar
+ 1
Thanks!! Really useful article.
16th Jul 2017, 4:53 AM
Alex Fanat
Alex Fanat - avatar