Skip to main contentCal State San Bernardino / [CNS] / [Comp Sci Dept] / [R J Botting] / [CSci320] [Search ]
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Sessions: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
10q.html (HTML) [10q.txt(Text)] Thu Apr 5 17:49:03 PDT 2007

Contents


    CS320/10 Questions on Subprograms and Chapter 9

      Question 1

      Here are some words used in the book. For each give the word or phrase used by a C or C++ programmer instead.
      1. Parameter, procedure, generic subprogram, program, subprogram header, subprogram definition

      Question 2 Ada Subprogram parameters

      a. What is Ada's rule about the semantics of in-out parameters

      b. What is wrong with Ada's rule?.

      c. Give examples of Ada's keyword parameters.

      d. Give advantages and disadvantages of keyword parameters.

      Question 3 Arguments in C and C++

      a. C uses "pass by value" for passing all arguments to functions. What does this mean?

      b. How do the "&" and "*" operators provide a form of "pass by reference".

      c. C++ added some extra parameter passing modes to those in C. What are they? How do they work?

      d. What is the advantage of C++'s additional parameter passing modes over C's?

      e. Rewrite the following C++ to get the same effect in C using "&" and "*" as C prefix operators:

        void flip( int & i) { i = ! i ; }
       ...
            int flop = 1;
       ...
            flip (flop);

      Code with tests [ 11flip.cpp ]

      Answer [ 11tester.cpp ]

      Question 4 Pass by Name

      a. Describe "pass by name" and name the language that introduced it.

      b. Give an example of how "pass by name" might be used in a special way.

      c. Why was it abandoned in Pascal and Algol 68?

      d. Does C/C++ #define provide call by name?

      e. Give a simple C/C++ program that will prove whether #define uses call by name or not!

      Question 5. Parameter Passing

      a. Describe one(1) parameter passing method.

      b. Name one language which has it or had it.

      c. Classify it according to its semantic mode: in, out, in-out.

      Question 6. Generics

      a. Name two(2) examples of languages that allow programmers to define generic subprograms.

      b. Show how to write a generic subprogram that returns the larger of two values in one of these languages.

      c. What are the advantages of generic subprograms?

      Question 7. Co-routines -- Deprecated

      a. How do co-routines differ from sub-programs.

      b. Name one language that provides co-routines.

    . . . . . . . . . ( end of section CS320/10 Questions on Subprograms and Chapter 9) <<Contents | End>>

End