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

1) What is “Dynamic Scoping”? 2) Consider the following C program: void main() {

ID: 3731493 • Letter: 1

Question

1) What is “Dynamic Scoping”?

2) Consider the following C program:

void main() {
int i, j, k;
. . .

}

void sub1() {
int j, k, l;
. . .

}

void sub2() {
int k, l, m;
. . .

}

void sub3() {
int l, m, n;
. . .

}

Given the following calling sequence and assuming that dynamic scoping is used, what variables are visible during execution of the last function called? Include with each visible variable the name of the function in which it was defined.

main calls sub2; sub2 calls sub3; sub3 calls sub1.

3)Define the following terms:

Data Type

Primitive Data Type

User-defined Data Type

Ordinal Type

Subrange Types

Strong Typing

4) In C/C++ what does an array name represent?

5)What is the difference between “Key Words” and “Reserve Words” in a programming language?

6)Describe the scope and lifetime of a stack-dynamic variable.

7)What is “Stack-Dynamic” binding of a scalar variable? Give an example.

8)Define “Short-circuit Evaluation” and “Operator Overloading”

in programming languages and give an example.

What are their impacts on readability?

9) What is Von Neumann Bottleneck?

10) What is the name of the category of programming languages whose structure is dictated by the von Neumann computer architecture?

11)What is coercions? Does it weaken reliability of a language? Explain.

12)Describe different categories of arrays based on binding of subscript range and memory allocations

State the advantage of each category.

Explanation / Answer

1)Answer:

Dynamic Scoping:

With dynamic scope, a global identifier refers to the identifier associated with the most recent environment, and is uncommon in modern languages. In technical terms, this means that each identifier has a global stack of bindings and the occurrence of a identifier is searched in the most recent binding.

In simpler terms, in dynamic scoping the compiler first searches the current block and then successively all the calling functions.

In dynamic scoping, by contrast, you search in the local function first, then you search in the function that called the local function, then you search in the function that called that function, and so on, up the call stack. "Dynamic" refers to change, in that the call stack can be different every time a given function is called, and so the function might hit different variables depending on where it is called from.

Dynamic scoping is useful as a substitute for globally scoped variables. A function can say "let current_numeric_base = 16; call other functions;" and the other functions will all print in hexadecimal. Then when they return, and the base-setting function returns, the base will return to whatever it was.

Dynamic scoping is a programming language paradigm that you don’t typically see. The scoping that most programmers are used to is called lexical scoping. It’s found in Lua and many other languages. Lexical scoping is the dominant choice for a reason: it’s easy to reason about and understand just by looking at the code. We can see what variables are in scope just by looking at the structure of the text in our editor. Scoping controls how a variable’s value is resolved.

Dynamic scoping does not care how the code is written, but instead how it executes. Each time a new function is executed, a new scope is pushed onto the stack. This scope is typically stored with the function’s call stack. When a variable is referenced in the function, the scope in each call stack is checked to see if it provides the value.

3)Answer:

Data type:

A data type, in programming, is a classification that specifies which type of value a variable has and what type of mathematical, relational or logical operations can be applied to it without causing an error. A string, for example, is a data type that is used to classify text and an integer is a data type used to classify whole numbers.

T

he data type of a value (or variable in some contexts) is an attribute that tells what kind of data that value can have. Most often the term is used in connection with static typing of variables in programming languages like C/C++, Java and C# etc, where the type of a variable is known at compile time. Data types include the storage classifications like integers, floating point values, strings, characters etc.

Data types define particular characteristics of data used in software programs and inform the compilers about predefined attributes required by specific variables or associated data objects.

Primitive Data Type:

A primitive data type is either a data type that is built into a programming language, or one that could be characterized as a basic structure for building more sophisticated data types. Programmers will often be immediately familiar with the primitive data types used in coding, which do not involve more sophisticated data sets for effective representation.

E

xamples of primitive data types include integers, floating point numbers and individual characters in text. Each of these primitive data types is an example of something that doesn’t require a large amount of data for representation. Characters simply correspond to a single reference point in an ASCII chart. Integers are numbers that do not need complex identifiers such as exponents and decimal points. Boolean values require only a binary choice between two possible values.

Other data types may or may not be primitive, depending on the design of a programming language or system. One common example is strings. A string variable is a collection of characters put together into a single dynamic variable. Programming languages work on strings to amend them as necessary. In this case, if a string is built into a program or has a particular kind of support, it could be called a primitive data type. However, it does not share some of the basic design elements of the primitive data types discussed above.

Other specific explanations of primitive data types include the idea that a primitive data type cannot be broken down into a simpler data type. Others explain primitive data types by contrasting them with user-defined classes, more sophisticated classes that are created by users, whereas primitive data types have already been created by the platform or interface that the programmer or developer is using. These explanations help to explain why one specific type of variable may be considered a primitive data type in one language but not in another. Other experts may contrast primitive data types with derived data types, which are created using collections of primitive data types. As a result, they can be broken down into more basic elements than the primitive data types.

User-defined Data Type:

A user-defined data type (UDT) is a data type that derived from an existing data type. You can use UDTs to extend the built-in types already available and create your own customized data types.

Ordinal Type:

ordinal data type is a data type with the property that its values can be counted. That is, the values can be put in a one-to-one correspondence with the positive integers.

For example, characters are ordinal because we can call 'A' the first character, 'B' the second, etc. The term is often used in programming for variables that can take one of a finite (often small) number of values. While the values are often implemented as integers (or similar types such as bytes) they are assigned literal names and the programming language (and the compiler for that language) can enforce that variables only be assigned those literals.

Subrange Types:

A subrange type defines a subset of the values of a particular type. By usingsubrange types, you can easily detect errors occuring due to unreasonable values of a variable which shouldn't take values outside a given boundary. Subrange typescan be defined of type character, integer, in no case real!

Strong typing:

A strongly-typed programming language is one in which each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data types.

5)Answer:

Ofcourse, const place is taken by final keyword in Java. goto is against to structured programming language where with goto, the Programmer looses control over the flow or the structure of coding.

Keywords : Keywords has some special functionalities to the compiler. So the keywords can not be used as identifiers in coding.

Reserved words: Reserve words are the words which are reserved for future use. In java, const and goto are the reserved words which are not being used currently and may be brought back to java in the future.

9)Answer:

Von Neumann Bottleneck:

The von Neumann bottleneck is the idea that computer system throughput is limited due to the relative ability of processors compared to top rates of data transfer. According to this description of computer architecture, a processor is idle for a certain amount of time while memory is accessed.

The von Neumann bottleneck is named after John von Neumann, a 20th century mathematician, scientist and computer science pioneer who was also involved in the Manhattan Project.

The von Neumann bottleneck looks at how to serve a faster CPU by allowing faster memory access. Part of the basis for the von Neumann bottleneck is the von Neumann architecture, in which a computer stores programming instructions, along with actual data, versus a Harvard architecture, where these two kinds of memory are stored separately. These types of setups became necessary as simpler, preprogrammed machines gave way to newer computers requiring better ways to control programming and information data.

Computer scientists have attempted to address the von Neumann bottleneck in various ways. One is to place critical memory in an easily accessible cache. There is also the idea of multithreading, or managing multiple processes in a triaged system. Other potential tools, like parallel processing, or changing the memory bus design, also work on the idea of decreasing this "bottleneck" or, in a phrase commonly used with this issue, increase the bandwidth for memory coming in and out of the processor.

Other ideas for "fixing" a von Neumann bottleneck are more conceptual. Experts have posited various "non-von Neumann" or "non-von" systems, some modeled around the biological world, which would allow for more distributed memory intake, versus the linear system used in conventional computing. Some ideas involve other emerging technologies, such as where a "memrister" or other nanoscale component could help with memory processing. The diversity of ideas around the von Neumann bottleneck show how integral this idea is to evaluating computing's potential as it has emerged over the last few decades