Skip to main content

Questions tagged [allocation]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
2 answers
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". ...
Vinz.R's user avatar
  • 39
1 vote
1 answer
5k 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 ...
Vinz.R's user avatar
  • 39
0 votes
3 answers
159 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));...
spirosbax's user avatar
0 votes
1 answer
26 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 ...
Lovish Ahuja's user avatar
0 votes
1 answer
106 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?
jaredcohe's user avatar
  • 103
1 vote
1 answer
779 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, ...
abelinux's user avatar
  • 1,170
0 votes
2 answers
169 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 ...
William Kenney's user avatar