In: Computer Science
QUESTION 1
1. We can solve memory leaks with
some form of garbage collection
such as mark-sweep or reference counters
some form of garbage collection
such as tombstones or lock-and-keys
using a tombstone or mark-sweep
approach to the dangling pointer problem
using a tombstone or lock and keys
approach to the dangling pointer problem
QUESTION 2
1. Pointers (and/or reference) types are necessary in
modern programming languages because
they provide the means to access
and manipulate dynamic storage
they aid readability and
reliabilty
otherwise everyone would be able to
program
they are easy to use and easy to
get right
QUESTION 3
1. What collection-type data type is most useful with
data values that are heterogeneous and may be processed
differently?
associative arrays
arrays
hashes
record data types
QUESTION 4
1. Booleans are NOT stored as a single bit
because
a single bit cannot be accessed
efficiently on many machines
simpler for the programmer to use a
byte rather than a bit
simpler for the compiler writer to
use a byte rather than a bit
space efficiency is better when
using bytes
QUESTION 5
1. Why is decimal a preferred type in financial
calculations?
financial firms have lots of money
and wanted their own type
decimal is a simpler encoding
decimal encodes exact amounts
whereas float and double are approximations
it's a smaller format
In case of any queries, please revert back.
QUESTION 1 :- We can solve memory leaks with
A.) Some form of garbage collection such as mark-sweep or reference
counters [mark and sweep are effective but not for memory
leaks]
B.) Some form of garbage collection such as tombstones or
lock-and-keys [These are the most common ways to solve memory
errors such as memory leaks. In Tombstone,A copy of Memory Stack is
kept safe. Hwever they take extra memory.]
C.) Using a tombstone or mark-sweep approach to the dangling
pointer problem[mark and sweep are effective but not for memory
leaks.]
d. ) Using a tombstone or lock and keys approach to the
dangling pointer problem [ANSWER: Smart pointers are often used
along with these to solve the problem of memories like memory
allocation.]
QUESTION 2 :- Pointers (and/or reference) types are necessary in
modern programming languages because
A.) they provide the means to access and
manipulate dynamic storage [ANSWER : This is because main function
of pointers is to provide the handling of control of memory to the
users.]
B.) they aid readability and reliabilty[They dont aid readability
at all]
C.) otherwise everyone would be able to program [Silly
Option!]
D) they are easy to use and easy to get right[Pointers add an
unnecessary overhead and complication. So, this is not right.]
QUESTION 3 :- What collection-type data type is most useful with
data values that are heterogeneous and may be processed
differently?
A.) associative arrays [This is a type of Map and stores relation
of one data type to other]
B.) arrays[They store all the elements of the same datatype and so
are homogeneous]
C.) hashes [Calculated hash codes for the same data type.]
D.) record data types [ANSWER : Can possess different types
of data in the same memory location]
QUESTION 4 :- Booleans are NOT stored as a single bit
because
A.) a single bit cannot be accessed efficiently on many
machines[ANSWER : Byte is often the smallest unit which can be
represented by address in memory. Bits cannot be shown in memory
and so Booleans are not stored in a single bit.]
B.) simpler for the programmer to use a byte rather than a bit[No,
this is a silly option]
C.) simpler for the compiler writer to use a byte rather than a bit
[A compiler can process both easily. Main problem is memory
allocation ]
D.) space efficiency is better when using bytes[Of course space
efficieny is better with bits with lower size]
QUESTION 5 :- Why is decimal a preferred type in financial
calculations?
A.) financial firms have lots of money and wanted their own
type[Silly Option]
B.) decimal is a simpler encoding [No, encoding of decimal is NOT
simple]
C.) decimal encodes exact amounts whereas float and double
are approximations [ANSWER : This is the correct option as
financial calculations needed precision levels which were not
received by fload and double.]
D.) it's a smaller format[No, it is NOT a smaller format than float
and doubles relativelty]