Sei sulla pagina 1di 4

 1 Typically, what is the largest permissible magnitude of an integer constant?

State
your answer in decimal, octal and hexadecimal.
Answer:

In decimal: The largest number you can represent with 8 bits is 11111111, or 255


in decimal notation.

In hex: In computing. The number 2,147,483,647 (or hexadecimal 7FFFFFFF16) is the


maximum positive value for a 32-bit signed binary integer in computing.

In octal: The largest digit in the octal number system is 7. The octal system is a base
eight number system, which means it uses eight digits: 0, 1, 2, 3, 4,...

2 What are unsigned integer constants? What are long integer constants? How do these
constants differ from ordinary integer constants? How can they be written and
identified?
Answer:

Unsigned integer constant: An unsigned integer constant specifies only positive integer value.


It is used only to count things. This constant can be identified by appending the letter u or U
to the end of the constant.

This constant can be identified by appending the letter u or U to the end of the constant. Long


integer constant: A long integer constant will automatically be generated simply by
specifying a constant that exceeds the normal maximum value.

Ordinary constants declarations are constructed using an identifier name followed by an “=”
token, and followed by an optional expression consisting of legal combinations of numbers,
characters, boolean values or enumerated values as appropriate. The following syntax
diagram shows how to construct a legal declaration of an ordinary constant.

Constant declaration

___________________________________________________________________

The compiler must be able to evaluate the expression in a constant declaration at compile
time. This means that most of the functions in the Run-Time library cannot be used in a
constant declaration. Operators such as +, -, *, /, not, and, or, div, mod, ord, chr, sizeof, pi,
int, trunc, round, frac, odd can be used, however

When a previously declared ordinary constant is used in the code, the compiler will insert the
actual value of the constant instead of the constant name. That is, the following two pieces of
code are entirely equivalent:
Const  
  One = 1;  
 
begin  
  Writeln(One);  
end.

3 Describe two different ways that floating-point constants can be written. What special
rules apply in each case?
Answer:

Numeric constants having decimal point are called floating point or real constants. Floating-
point constants can be written in two forms:

1. Fractional forms
2. Exponential form or Scientific notation

Here are the rules for creating floating point constants in Fractional form:

1. Must have one at least one digit


2. Must have a decimal point
3. Can be positive or negative, the default is positive
4. No comma, blanks, or any other symbols are allowed

Here are some examples:

1 3.14
2 899.0
3 -0.999
Exponential form is used in cases when a number is too small or too large. For
example, 0.00000941 can be represented as 9.41e-6. The part of the number before e is called
mantissa i.e 9.41, whereas, the part following e is called the exponent i.e -6.

Here are the rules for creating floating point constants in Exponential form:

1. Mantissa and exponent must be separated by e or E.


2. Mantissa can be positive or negative, default is positive.
3. Exponent must have at least one digit.
4. The exponent can be positive or negative default is positive

Some examples of floating point numbers in exponential form are:

1 100.34e4
2 -56E10
3 0.233E10
4 -0.94e15
4 What is the purpose of the (optional) exponent in a floating-point constant?
Answer:

In decimal, very large numbers can be shown with a mantissa and an exponent. i.e. 0.12*10²
Here the 0.12 is the mantissa and the 10² is the exponent. the mantissa holds the main digits
and the exponents defines where the decimal point should be placed. The same technique can
be used for binary numbers.

5 Typically, what is the largest permissible magnitude of a floating-point constant?


Compare with an integer constant.
Answer:

6 How can “single-precision” and “long” floating-point constants be written and


identified?
Answer:

The ANSI standard for C has a provision that allows expressions to be evaluated in single-
precision arithmetic if there is no double (or long double) operand in the expression. The C
compiler supports this provision.

Floating point constants are double-precision, unless explicitly stated to be float. For
example, in the statements

float a,b;
...
a = b + 1.0;
because the constant 1.0 has type double, b is promoted to double before the addition and the
result is converted back to float. However, the constant can be made explicitly a float:
a = b + 1.0f;
/* or */
a = b + (float) 1.0;

7 Typically, how many significant figures are permitted in a floating-point constant?


Answer:

Float values have between 6 and 9 digits of precision, with most float values having at least
7 significant digits. Double values have between 15 and 18 digits of precision, with most
double values having at least 16 significant digits.

8 Describe the differences in accuracy between integer and floating-point constants.


Under what circumstances should each type of constant be used?
Answer:

Integer literals represent fixed integer values like 900, 12, 400, -222 etc. (with in
the integer range). Whereas, floating point literals represents fractional values i.e. numbers
with decimal values like 25.53, 45.66, 58.66 etc. while writing these literals we should use
the notation f or F as 25.53

Potrebbero piacerti anche