what is the point of dynamic allocation in c? (plus dont get triggered. please explain why im wrong)
What are good projects to get comfortable with dynamic memory and pointers in general?
Best Tutorials on Coding Your Own Dynamic Memory Management System
Dynamic Memory Allocation
Can I use dynamic memory allocation for arrays and structures
How does dynamic memory allocation differ from stackbased memory allocation
How does dynamic memory allocation impact performance
Videos
So lets say i do int x=5; so i create a variable of 4 bytes that stores a value of 5
then i do int *y= malloc(sizeof(int)); here i created a pointer that gave me a memory location in the RAM and i can do *y=5; to store 5 in it. What exactly is the benefit of using dynamic allocation here?
plus in case of strings how do i dynamically allocate just enough memory to store name of some guy in c without knowing it before hand how long the name is?
like char name[4]; means i have an array of 5 char out of which im supposed to use 4. But here i need to make sure name is of length 4 always.
but char *name = malloc(5*sizeof(char)); dynamically allocates the same memory but i still need to make sure length of name stays 4 plus one extra for the null.
how is this implemented to take values of any length?