Pset4 submission problems
For people having trouble submitting the .zip file for pset4:
1) One option is to remove the SPL library from the folder and then zipping and submitting.
2) In case you haven't, or you have and it still looks like the file doesn't finish uploading, open a second tab, and check if the submission appears. In most cases it will, and ...
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 ...
I'm not sure you needed to learn about pointers and memory management in order to solve hacker 2. I think you've gone a little bit far. However, I'm gonna try answering your questions.
A pointer is basically a variable that stores an address of a location in memory. Pretty much every type has its own pointer type. For example, char has char *, int has int *,...
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
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 ...
Disclaimer: I am not part of CS50 team, and don't know their reasoning. This is my opinion, why I think that has been a good idea, especially when touching currently trendy topics like "machine learning".
Both are used by people for command-line scripts and web stuff. There are also a few GUI programmes written in Python, haven't encountered one written in ...
INT02-C. Understand integer conversion rules
Conversions can occur explicitly as the result of a cast or implicitly
as required by an operation. Although conversions are generally
required for the correct execution of a program, they can also lead to
lost or misinterpreted data. Conversion of an operand value to a
compatible type causes no ...
Looks like C is (internally) casting the constant 2 (or probably more correctly, the result of n - 2) as an int since that is the essential difference between the two printfs.
You might search the internet-at-large for "C integer promotion rules". There are a lot of hits on the subject. This might be an interesting place to start.
To answer your question:
What I don't understand is, when it comes to i = 1, how is it that the
fread function in the second for loop does not again start at the
beginning of the first but of the second line of the infile?
This is because the fread function also updates the cursor every time fread is called. This cursor is stored independently of ...