GSLC DATA TYPES

GSLC DATA TYPES

 

  1. What are the advantages and disadvantages of decimal data types?
    2. How does a decimal value waste memory space?
    3. In what way is static type checking better than dynamic type checking?
    4. What is coercion in programming languages?
    5. Explain how coercion rules can weaken the beneficial effect of strong typing?

 

  1. Advantages :

able to precisely store decimal values at least those within a restricted range, which can’t be done with floating-point

Disadvantages :

range of the value is restricted because no exponents are allowed, and their representation in memory is mildly wasteful.

 

  1. Decimal types are stored using binary codes for the decimal digits. These representations are called binary coded decimal (BCD). They take more storage than binary representations. It takes at least four bits to code a decimal digit.
    Therefore, to store a six-digit coded decimal number requires 24 bits of memory.
    However, it takes only 20 bits to store the same number in binary.
    Decimal values store numeric information as digits encoded using the four bit binary equivalents: 0 (0000) to 9 (1001). That means a single byte can hold values between 0 and 99. But simply using the same byte to hold a binary value will yield values between 0 and 255 (or –128 and +127).

 

  1. The benefit of static type checking is it allows type errors to be caught early in development cycle. Usually static type checking results in compiled code that run more quickly because when the compiler knows the exact data types that are in use, it can produce optimized machine code (i.e. faster and/or using less memory). Static type checkers evaluate only the type information that can be determined at compile time, but are able to verify that the checked conditions hold for all possible executions of the program, which eliminates the need to repeat type checks every time the program is executed.

 

  1. Coercion is automatic conversion of value to to another of different data type and vice versa where it is appropriate. Also called implicit conversion.

For example:

double x, y;

x = 3;            // implicitly coercion (coercion)

y = (double) 5;   // explicitly coercion (casting)

 

  1. A language that allows many type coercions can weaken the beneficial effect of strong typing by allowing many potential type errors to be masked by simply coercing the type of an operand from its incorrect type given in the statement to an acceptable type, rather than reporting it as an error.

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *