Chapter 9
30 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is a fundamental characteristic of subprograms?

  • Subprograms have no entry points
  • Subprograms have entry points determined at runtime
  • Subprograms can have multiple entry points
  • Each subprogram has a single entry point (correct)
  • When does control return to the caller in subprograms?

  • When the called subprogram's execution terminates (correct)
  • When the called subprogram is suspended
  • Control returns randomly to the caller
  • Control never returns to the caller
  • What are the two fundamental abstraction facilities discussed in the chapter?

  • Process control and Data management
  • Data abstraction and Control abstraction
  • Process abstraction and Control abstraction
  • Process abstraction and Data abstraction (correct)
  • Which parameter passing method involves passing an access path, providing efficient passing but with potential disadvantages related to slower accesses and potential unwanted side effects?

    <p>Pass-by-reference</p> Signup and view all the answers

    What type of languages allow formal parameters to have default values and accept variable numbers of parameters?

    <p>C#</p> Signup and view all the answers

    What are the models of parameter passing that include modes such as in, out, and inout, each with its own semantic and conceptual implications?

    <p>Pass-by-argument</p> Signup and view all the answers

    Which language supports generic methods similar to Java 5.0 but does not support wildcards?

    <p>C# 2005</p> Signup and view all the answers

    In which language are operators overloaded?

    <p>Ruby</p> Signup and view all the answers

    Which language demonstrates closures using nested anonymous functions?

    <p>JavaScript</p> Signup and view all the answers

    Which language supports generic parameters to be defined without type constraints?

    <p>F#</p> Signup and view all the answers

    Which language directly supports coroutines, providing quasi-concurrent execution of program units?

    <p>Lua</p> Signup and view all the answers

    Which language has differences in generics compared to C++, such as the requirement for generic parameters to be classes and the ability to specify restrictions on the range of classes passed to the generic method?

    <p>Java 5.0</p> Signup and view all the answers

    Which statement accurately describes parameter passing in C++?

    <p>In C++, the address is passed directly for pass-by-reference.</p> Signup and view all the answers

    What is a key difference in parameter passing between C and C++?

    <p>In C, parameters are passed by value, and pass-by-reference is achieved using pointers as parameters. In C++, a special pointer type called reference type is used for pass-by-reference.</p> Signup and view all the answers

    What is a consideration for parameter passing that often conflicts with efficiency in programming languages?

    <p>One-way or two-way data transfer</p> Signup and view all the answers

    Which language supports generic methods similar to Java 5.0 but does not support wildcards?

    <p>C++</p> Signup and view all the answers

    Which language demonstrates closures using nested anonymous functions?

    <p>JavaScript</p> Signup and view all the answers

    Which language directly supports coroutines, providing quasi-concurrent execution of program units?

    <p>Lua</p> Signup and view all the answers

    In which language are operators overloaded?

    <p>Python</p> Signup and view all the answers

    Which language has differences in generics compared to C++, such as the requirement for generic parameters to be classes and the ability to specify restrictions on the range of classes passed to the generic method?

    <p>Java</p> Signup and view all the answers

    Which language supports generic methods similar to Java 5.0 but does not support wildcards?

    <p>C# 2005</p> Signup and view all the answers

    Which language directly supports coroutines, providing quasi-concurrent execution of program units?

    <p>Python</p> Signup and view all the answers

    Which language demonstrates closures using nested anonymous functions?

    <p>JavaScript</p> Signup and view all the answers

    Which language has differences in generics compared to C++, such as the requirement for generic parameters to be classes and the ability to specify restrictions on the range of classes passed to the generic method?

    <p>Java</p> Signup and view all the answers

    Which statement accurately describes parameter passing in C++?

    <p>C++ generates versions of a generic subprogram implicitly when it is named in a call or when its address is taken with the &amp; operator</p> Signup and view all the answers

    What type of polymorphism allows a variable of type T to access any object of type T or any type derived from T in OOP languages?

    <p>Subtype polymorphism</p> Signup and view all the answers

    What do closures consist of?

    <p>A subprogram and its referencing environment</p> Signup and view all the answers

    What are coroutines?

    <p>Subprograms with multiple entries and control their own execution</p> Signup and view all the answers

    What is the characteristic of overloaded subprograms?

    <p>They provide ad hoc polymorphism</p> Signup and view all the answers

    What do generic or polymorphic subprograms do?

    <p>They take parameters of different types on different activations</p> Signup and view all the answers

    Study Notes

    Parameter Passing in Programming Languages

    • In C, it is possible to change the passed reference in the called subprogram, but in some other languages like Pascal and C++, formal parameters that are addresses are implicitly dereferenced, preventing such changes.
    • Most languages implement parameter communication through the runtime stack, with pass-by-reference being the simplest to implement by placing only an address in the stack.
    • In C, passing by reference is mimicked by first passing the value of the pointer, while in C++, the address is passed directly, which is the real passing by reference.
    • In C, parameters are passed by value, and pass-by-reference is achieved using pointers as parameters. In C++, a special pointer type called reference type is used for pass-by-reference. In Java, all non-object parameters are passed by value, and object parameters are passed by reference.
    • Fortran 95+ allows parameters to be declared in, out, or inout mode, while in C#, pass-by-reference is specified by preceding both a formal parameter and its actual parameter with "ref".
    • Type checking of parameters is considered important for reliability, with languages like Pascal and Java always requiring type checking, while Perl, JavaScript, and PHP do not require it, and Python and Ruby do not have parameter type checking due to variables not having types.
    • When a multidimensional array is passed to a subprogram and separately compiled, the compiler needs to know the declared size of the array to build the storage mapping function.
    • In C and C++, the programmer is required to include the declared sizes of all but the first subscript in the actual parameter, disallowing writing flexible subprograms. In Java and C#, arrays are objects, and each array inherits a named constant set to the length of the array when the array object is created.
    • Two important considerations for parameter passing are efficiency and one-way or two-way data transfer, which are often in conflict.
    • Indirect calls to subprograms, such as event handling and GUIs, are made through function pointers in C and C++.
    • Design issues for functions include whether side effects are allowed and the types of return values allowed. Most imperative languages restrict the return types, with C++ allowing any type except arrays and functions, and Java and C# allowing any type for methods.
    • Overloaded subprograms, which have the same name as another subprogram in the same referencing environment, are included in languages like C++, Java, C#, and Ada, with each version having a unique protocol. Ada, Java, C++, and C# allow users to write multiple versions of subprograms with the same name, and function signature is determined by the type and number of parameters.

    Generic Subprograms and Other Language Features

    • Generic or polymorphic subprograms can take parameters of different types on different activations
    • Overloaded subprograms provide ad hoc polymorphism
    • Subtype polymorphism allows a variable of type T to access any object of type T or any type derived from T in OOP languages
    • C++ generates versions of a generic subprogram implicitly when it is named in a call or when its address is taken with the & operator
    • Java 5.0 has differences in generics compared to C++, such as the requirement for generic parameters to be classes and the ability to specify restrictions on the range of classes passed to the generic method
    • C# 2005 supports generic methods similar to Java 5.0 but does not support wildcards
    • F# infers generic types and allows generic parameters to be defined without type constraints
    • Operators can be overloaded in Ada, C++, Python, and Ruby
    • A closure is a subprogram and its referencing environment, necessary if the subprogram can access variables in nesting scopes and be called from anywhere
    • JavaScript and C# both demonstrate closures using nested anonymous functions and delegates, respectively
    • Coroutines are subprograms with multiple entries and control their own execution, supported directly in Lua
    • Coroutines provide quasi-concurrent execution of program units, with execution interleaved but not overlapped

    Generic Subprograms and Other Language Features

    • Generic or polymorphic subprograms can take parameters of different types on different activations
    • Overloaded subprograms provide ad hoc polymorphism
    • Subtype polymorphism allows a variable of type T to access any object of type T or any type derived from T in OOP languages
    • C++ generates versions of a generic subprogram implicitly when it is named in a call or when its address is taken with the & operator
    • Java 5.0 has differences in generics compared to C++, such as the requirement for generic parameters to be classes and the ability to specify restrictions on the range of classes passed to the generic method
    • C# 2005 supports generic methods similar to Java 5.0 but does not support wildcards
    • F# infers generic types and allows generic parameters to be defined without type constraints
    • Operators can be overloaded in Ada, C++, Python, and Ruby
    • A closure is a subprogram and its referencing environment, necessary if the subprogram can access variables in nesting scopes and be called from anywhere
    • JavaScript and C# both demonstrate closures using nested anonymous functions and delegates, respectively
    • Coroutines are subprograms with multiple entries and control their own execution, supported directly in Lua
    • Coroutines provide quasi-concurrent execution of program units, with execution interleaved but not overlapped

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    CSI3120A_Fall2023_Lecture8.pdf

    Description

    Test your knowledge of parameter passing in programming languages with this quiz. Explore the nuances of pass-by-value, pass-by-reference, parameter communication, type checking, array passing, subprogram design issues, and more.

    More Like This

    Chapter 9: Families and Children
    15 questions
    Chapter 9: Meaning of Life Flashcards
    8 questions
    Chapter 9 Vocabulary Flashcards
    10 questions

    Chapter 9 Vocabulary Flashcards

    MatchlessAltoSaxophone avatar
    MatchlessAltoSaxophone
    Use Quizgecko on...
    Browser
    Browser