TPL 6 Chapter (Short Answers) : Use Postfix Notation Two Programming Languages
TPL 6 Chapter (Short Answers) : Use Postfix Notation Two Programming Languages
TPL 6 Chapter (Short Answers) : Use Postfix Notation Two Programming Languages
3. Explain the difference between prefix, infix, and postfix notation. What is
Cambridge Polish notation? Name two programming languages that use
postfix notation?
In the infix expressions, it is difficult to keep track of the operator precedence whereas
here the postfix expression itself determines the precedence of operators (which is
done by the placement of operators)i.e the operator which occurs first operates on the
operand. The main difference between prefix and postfix is that the prefix is
a notation that writes the operator before operands while the postfix is a notation that
writes the operator after the operands. Notation is the way of writing arithmetic
expressions.
R-Value: Right hand side of assignment that provides the new value. Usually the result of
evaluation and expressions.
These two steps can be combined. When a variable is defined, you can also provide an
initial value for the variable at the same time. This is called initialization.
C++ supports three basic ways to initialize a variable. First, we can do copy
initialization by using an equals sign:
1 int width = 5; // copy initialization of value 5 into variable width
E.g.
int i;
int j=5;
if(j > 0)
i=2;
else
17. Why do most languages leave unspecified the order in which the
arguments of an operator or function are evaluated?
So the code can be generated at compile time for the loop control. The size of the loop is
known , so step-size needs to be available at compile time as well.
19. List the principal uses of goto, and the structured alternatives to each.
It performs a one-way transfer of control to another line of code; in contrast a function call
normally returns control.
Most modern languages provide an explicit return statement. Where once a goto might have
been used to escape from the middle of a loop , most modern languages provide a break or
exit. More significantly, several languages allow a program to return form a nested chain of
subroutine calls in a single operation that propagates out to some surrounding context s.
21. What are continuations? What other language features do they subsume?
It consists of code address and a referencing environment to be rested when jumping to that
address.
A continuation is an abstraction that captures a context in which execution might continue.
Obviously rand needs to have a side effect, so that it will return a different value each time it is
called. One could always recast it as a procedure with a reference parameter.
26. Describe three different search strategies that might be employed in the
implementation of a case statement, and the circumstances in which each
would be desirable.
Sequential testing, Hashing, and binary search.
Sequential testing (as in an if… then … else statement) is the method of choice if the total
number of case statement labels is small. It runs in time O(n), where n is the number of labels.
A hash table is attractive if the range of label values is large, but has many missing values and
no large ranges. With an appropriate hash function it will run in time O(1). Unfortunately, A
hash table requires separate entry for each possible value of the tested expression, making with
large value range.
Binary search can accommodate ranges easily . It runs in time O(log n), With a relatively low
constant factor
30. Describe the “iteration count” loop implementation. What problem(s) does
it solve?
Iteration count involve pre-computing the number of iterations that will take place in the loop
based on the step, and then decrementing this number.
Removes the problem of determining the sign of the step and figuring out how to implement it.
This is precomputed.
31. What are the advantages of making an index variable local to the loop it
controls?
34. Explain the difference between true iterators and iterator objects.
True iterators represents a subroutine that is permitted to contain yield statements, each of
which produces loop index value.
35. Cite two advantages of iterator objects over the use of programming
conventions in a language like C.
No yield statement and no separate thread-like context to enumerate values. Ordinary objects
that provides methods for initialization, generation of next index value , and texting for
completion.