Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Ada, declarations of named constants have the option of omitting the type of

ID: 3805125 • Letter: I

Question

In Ada, declarations of named constants have the option of omitting the type of the constant, as illustrated by the following examples: N: constant Integer: = 100; -- Type of constant is specified N: constant Integer: = 100; -- Type of constant is omitted (a) Are both kinds of declarations allowed for all constants, or are there any cases where only one kind is allowed? (b) What differences are there, if any, in what expressions are allowed as the value of a constant? (c) What differences are there, if any in how the constants can be used?

Explanation / Answer

a) FOR THE known query BOTH DECLARATIONS ARE ALLOWED:

b)   present are a variety of exact realization of the universal idea of a stable, with slight distinction that are frequently unnoticed. The most important are: compile time (statically valued) constants, run time (dynamically valued) constants, unchallengeable substance, and constant type (const).

const float PI = 3.1415927; // maximal single float precision

const unsigned int MTU = 1500;

Typical examples of run time constants are values intended based on inputs to a function, such as this C++ example:

void f(std::string s) {

const size_t l = s.length();

// ...

c) Constants are helpful for together programmers and compilers:

for programmers they are a form of self document code and allow way of thinking about rightness; while for compilers they allow compile time and run time checks that faithfulness assumption are not dishonored, and allow or make simpler some compiler optimizations.