What is the differencd | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the differencd

Int *p = (int*)malloc(sizeof(int)*100) and int arr[100] ; int *p = arr....what is the difference?

28th Dec 2020, 8:22 PM
1 Answer
+ 4
when you use malloc, you are dynamically allocating the memory to your int-type pointer in this example. By doing so, you can for example ask user for the size of an array, and make an array of size declared by user, which is not possible when you make arrays statically (int arr[100]; in your example) . Of course there is more to tell about pointers, but YouTube or some other users will explain it better than me
28th Dec 2020, 8:48 PM
Michal Doruch