McConnell_2004_Ch12_Fundamental_Data_Types Flashcards
What is a fundamental data type…?
They are the basic building blocks for all other data types.
Discuss reasons for avoiding “magic numbers”…?
Avoiding magic numbers yields three advantages:
- Changes can be made more reliably.
- Changes can be made more easily.
- Your code is more reable.
What is “integer overflow” and how is it best prevented?
When doing integer multiplication or addition, you need to be aware of the largest possible integer. The largest possible unsigned integer is often 2^32 -1 and is sometimes 2^16 -1, or 65,535. The problem comes up when you multiply two numbers that produce a number bigger than the maximum integer.
The easiest way to prevent integer overflow is to think through each of the terms in your arithmetic expression and try to imagine the largest value each can assume.
Complete the sentence. “the main consideration in using floating point numbers is…“…?
that many fractional decimal numbers can’t be represented accurately using the 1s and 0s available on a digital computer. Non-terminating decimals like 1/3 or 1/7 can usually be represented to only 7 or 15 digits of accuracy. in my version of Microsoft Visual Basic, a 32-bit floating-point representation of 1/3 equals 0.33333330. It’s accurate to 7 digits. This is accurate enough for most purposes but inaccurate enough to trick you sometimes.
Why may the following function be necessary? equals( term1 : Real; term2 : Real ) : Boolean; constants ACCEPTABLE = 0.00001; vars difference : Real; begin difference := term1 - term2; difference := difference.abs; if ( difference
page 296 I DON”T UNDERSTAND!!!!
Describe the alternative to using STRING LITERALS and explain the reasoning using this alternative…?
String literals tend to take up a lot of space. They’re used for menus, messages, help screens, entry forms, and so on. If you have too many, they grow beyond control and cause memory problems. String space isn’t a concern in many environments, but in embedded systems programming and other applications in which storage space is at a premium solutions to string-space problems are easier to implement if the strings are relatively independent of the source code.
What is an ENUMERATED TYPE and how can they be replaced in a programming language like Jade which does not have them…?
An enumerated type is a type of data that allows each member of a class of objects to be described in English. Enumerated types are available in C++ and Visual Basic and are generally used when you know all the possible values of a variable and want to express them in words.
In languages that don’t support classes, you can achieve the same basic effect through discipline use of global variables for each of the elements of the enumeration.