[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] /[CS320 Course Materials] /10q.html [10q.txt(Text)] [Search ]
Thu May 2 17:10:10 PDT 2013
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CS320/10 Questions on Subprograms and Chapter 9

      Question 1 Define key terms

      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 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 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 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 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 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>>

    Review

( End of document ) <<Contents | Top