+ 2

Hello, can someone explain me, why us needs the pointer in c language and the importance of the malloc()? Thanks !

C programim

6th Nov 2021, 2:11 PM
Kady
3 odpowiedzi
+ 5
Sometimes in some cases you can't use normal variables. Let me mention some. 1) You want to allocate some memory dynamically through malloc() or calloc() function. Now how do you get the memory block that was allocated inside that function? 2) You want to pass a variable to a function but also you want to be able to modify the variable. Now how do you do this? Because when you just pass the variable, only a copy of it is passed to the function and modifying it won't change the variable's value. So in these cases, we use a pointer to the memory location of the variable that we use, so that we can access it(like with normal variables) and also modify it. Pointers play a huge role in C programming, so make sure to understand them right. For complete understanding on pointers, refer the below resource. All the best =) https://youtube.com/playlist?list=PL2_aWCzGMAwLZp6LMUKI3cc7pgGsasm2_
6th Nov 2021, 2:20 PM
Rishi
Rishi - avatar
+ 2
kadrije Kashari happy to help =)
6th Nov 2021, 2:24 PM
Rishi
Rishi - avatar
+ 1
Thank you 😊
6th Nov 2021, 2:22 PM
Kady