1 Typically
1 Typically
1 Typically
State
your answer in decimal, octal and hexadecimal.
Answer:
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:
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 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 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.
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;
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.
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