Hot answers tagged

4

Yes, when you use a free(px); call, it frees the memory that was malloc'd earlier and pointed to by px. The pointer itself, however, will continue to exist and will still have the same address. It will not automatically be changed to NULL or anything else. The only thing that will remove the pointer var from the stack would be if it went out of scope, just ...


2

The answer of our friend @NullityNull is correct, as long as realloc succeeds and works well. Your question is interesting. Consider the following program fragment char *string; string = (char *)malloc(100); string = NULL; One of the most common failure when memory is managed explicitly is what is known as "memory leak". This situation occurs when a ...


2

If realloc can't resize the memory block you pass in, it makes a new one, copies the data, and deallocates the old one. If I were you I'd read up a bit on specification for Realloc and malloc.


2

In addition to the points made by @MARS and @NullityNull, there are advantages and disadvantages to both methods. Allocating memory on the stack is more convenient because it automatically cleans up after itself when the variable is no longer in scope. Sometimes this is called "garbage collection". However, this convenience comes at a cost of fixed size: ...


1

You could add a class attribute to the <tr> element and then add CSS directives for each (or a specific) type. It would be something like <tr class="{{ row['type'] }}"> in the html and in the css (or the style element in layout.html): .type1 { background-color: green; }


1

Recursion isn't done right. For example, your function meant to return an int might end without returning anything. Essence of recursion is that you define a base case (like for example rod of length 0 is worth nothing), and assume a sub-problem closer to that base case (shorter rod) can already be solved. Like you get a rod of length 10, and assume the ...


1

Yes it's true that for simplicity's sake, in the first psets, we din't free() the strings allocated by GetString() and that caused memory leaks. Nevertheless, most modern operating systems can see when a program exists with memory leaks, and frees the memory itself. So even if you run your program a million times you would not notice any memory shortage (...


Only top voted, non community-wiki answers of a minimum length are eligible