SFT 221
Workshop 4
Name: Kashish Verma
ID: 151579232
Email: kverma45@[Link]
Section: ZBB
1.
When I tackled the bugs, my first step was to run the code through Visual Studio's
compiler to catch any basic syntax errors. While this helped with minor issues, the
real progress came from reasoning and thinking deeply about how numbers and
computer memory interact. By considering the limitations of data types and the
constraints of computer memory, I could predict where problems might arise,
particularly with overflow when dealing with large factorial values.
2.
a). The largest integer value that can be stored depends on the data type being
used. For example, an int typically has a maximum value of 2,147,483,647, while a
long long int can store much larger values, up to 9,223,372,036,854,775,807. As for
double values, the largest representable value is typically around 1.79769e+308.
b). Variables have limits on how big a number they can hold because computers
have limited memory. Using more memory than necessary would waste resources
and make things complicated. So, we use just enough memory to cover the
expected range of values for each type of variable to keep things efficient.
c). If you go past the highest number an integer can hold, it causes overflow. This
can make the value suddenly become negative, which breaks what the program
expects and might make it act strange.
d). Floating-point numbers use IEEE 754 format. It has three parts: a sign bit (for
positive or negative), an exponent (to show the size), and a mantissa (for the
digits). This is different from integers, which just use bits to show the whole number
value without separate parts for exponent or mantissa.
3.
The default stack memory given to my C or C++ program in Visual Studio is usually
around 1 MB. The default heap size varies, but it's typically larger than the stack
size.
In the factorial code, the factorial values exceed the available stack memory, and
cause a stack overflow, leading to a program crash. Increasing the amount of
memory allocated to the program could fix these issues, but it's not always a
complete solution. Adding more memory could help, but it's not always enough.
Memory limits exist to keep things stable and fair for all programs running on the
system.