Skip to content
Snippets Groups Projects

Initial commit for 2-StudentDB

13 files
+ 479
0
Compare changes
  • Side-by-side
  • Inline

Files

+ 29
0
 
## Assignment 2 Answers
 
 
### 1. Is externalizing `get_student(...)` into its own function a good design strategy?
 
 
**Answer:** Yes, putting `get_student(...)` in its own function is a good idea because it keeps the code neat and organized. It makes the program easier to understand, fix, and use again in other parts of the code.
 
 
### 2. Why is returning a pointer to a local variable a bad idea in C?
 
 
**Answer:** It’s a bad idea because the variable exists only while the function is running. After the function finishes, the memory is gone, and the pointer will point to nothing useful. This can cause errors that are hard to find.
 
 
### 3. Thoughts on using `malloc()` for `get_student(...)`?
 
 
**Answer:** Using `malloc()` works because the memory stays even after the function ends. But the problem is you have to remember to free the memory later. If you forget, it can cause memory leaks. Also, using `malloc()` too much can slow down the program.
 
 
### 4. Understanding File Size and Disk Usage
 
 
#### a. Why does `ls` show increasing file sizes after adding students?
 
 
**Answer:** The `ls` command shows the file size based on where the data is written. When we add students, the file grows because each student’s information takes up space. Bigger student IDs make the file size jump because the data is stored further in the file.
 
 
#### b. Why does disk usage (`du`) stay the same until we add student ID 64?
 
 
**Answer:** The disk uses blocks (like small storage boxes) of 4K size. As long as the data fits in the same box, the space used doesn't change. When we add student ID 64, we need a new box, so the disk space used goes from 4K to 8K.
 
 
#### c. Why does adding student ID 99999 make the file size huge but use little disk space?
 
 
**Answer:** The file looks huge because the data is written far apart, leaving big empty spaces. These empty spaces don’t take up real disk space. That’s why the file size is large, but the disk usage is small.
 
 
Loading