Questions tagged [allocation]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
2answers
1k views

What will realloc() do if the contiguous memory location is already occupied?

Consider- char* name1 = malloc(4 * sizeof(char)); name1 = "Mike"; Now if i want to put "Mike Smith" in the same string "name1", I need 6 more bytes of memory (one for the space and 5 for "Smith". ...
1
vote
1answer
2k views

When we free a dynamically allocated memory, what happens to the pointer pointing at it?

After watching section on "Dynamically allocated memory" (from Week 4) several times, I still have a question unanswered. Consider the following code- // Allocates 4 bytes of memory on heap and ...
0
votes
3answers
139 views

Week 4, Section : Dynamic Memory Allocation

After watching Dynamic Memory allocation section and reading this i am a bit confused, if declaring an array int array[10]; and allocating using malloc int* parray = malloc(10 * sizeof(int));...
0
votes
1answer
23 views

Regarding week4's lecture video

l have just seen the week4's lecture video where it has been cleared out that string is actually char* under the hood! Then, I encountered and example where why he tries to copy a string by assigning ...
0
votes
1answer
71 views

Memory allocation when working with files in C

When you fopen a file in C, and you write to it, how is there memory waiting for the additional data? What happens if the file doesn't have free space after it?
1
vote
1answer
672 views

Memory allocation: recommended practices

I'm rambling a little with hacker 2 (the passwords') and, in the meantime, gained some insight about pointers, mem-alloc, 'valgrind', etc... It's been a truly great, challenging experience. But, ...
0
votes
2answers
136 views

memory leak on the stack?

Just wondering if anyone can explain why we are concerned with memory leak in the heap (freeing for example a char *), but we are not concerned with freeing variables that are in the stack in the main ...