Exercises For Section 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

1.1.1 Exercises for Section 1.

1
Exercise 1.1.1 : What is the difference between a compiler and an interpreter?

Exercise 1.1.2 : What are the advantages of (a) a compiler over an interpreter (b) an interpreter over
a compiler?
Exercise 1.1.3 : What advantages are there to a language-processing system in which the compiler
produces assembly language rather than machine language?
Exercise 1.1.4 : A compiler that translates a high-level language into another high-level language is
called a source-to-source translator. What advantages are there to using C as a target language for a
compiler?
Exercise 1.1.5 : Describe some of the tasks that an assembler needs to perform.
Exercises for Section 1.3
Exercise 1.3.1: Indicate which of the following terms:

a) imperative b) declarative c) von Neumann d) object-oriented e) functional f) third-


generation g) fourth-generation h) scripting

apply to which of the following languages:


1) C 2) C++ 3) Cobol 4) Fortran 5) Java 6) Lisp 7) ML 8) Perl 9) Python 10) VB.
Exercises for Section 1.6
Exercise 1.6.1: For the block-structured C code of Fig. 1.13(a), indicate the values assigned to
w, x, y, and z.
Exercise 1.6.2: Repeat Exercise 1.6.1 for the code of Fig. 1.13(b).
Exercise 1.6.3: For the block-structured code of Fig. 1.14, assuming the usual static scoping
of declarations, give the scope for each of the twelve declarations.
(b) Code for Exercise 1.6.2
z = i + j; } y = i + j; i = 7; { int j = 6; x = i + j; } w = i + j; { int i = 5; int i = 3; int j = 4; int w, x, y, z;
(a) Code for Exercise 1.6.1
z = i + j; } y = i + j; { int i = 8; x = i + j; } w = i + j; i = 6; { int j = 7; int i = 4; int j = 5; int w, x, y, z;
Figure 1.13: Block-structured code
{ int w, x, y, z; /* Block B1 */ { int x, z; /* Block B2 */ { int w, x; /* Block B3 */ } } { int w, x; /*
Block B4 */ { int y, z; /* Block B5 */ } } }
Figure 1.14: Block structured code for Exercise 1.6.3
Exercise 1.6.4: What is printed by the following C code?
#define a (x+1) int x = 2; void b() { x = a; printf("%d\n", x); } void c() { int x = 1; printf("%d\n",
a); } void main() { b(); c(); }

You might also like