Kablow!

Subprograms: functions and procedures

விளையாடிக் கற்றுக்கொள்ளுங்கள்

ஆற்றல் சம்பாதிக்க இந்த கேள்விகளுக்குப் பதிலளியுங்கள், பின்னர் மீன் பிடித்து ஆராயுங்கள். கணக்கு தேவையில்லை.

கல்வியாளர்களுக்கு: Subprograms: functions and procedures (Computer Science, Programming)-க்கான தயாரான பாட ஸ்லைடுகள், திருப்புதல் குறிப்புகள் — உங்கள் பாடத்தில் அவற்றைப் பயன்படுத்தவும், அல்லது கற்பவர்கள் நேரலை விளையாட்டாக விளையாடும் ஊடாடும் வகுப்பு செயல்பாடாக தலைப்பை இயக்கவும்.

பாட குறிப்புகள்

Why subprograms?

  • A subprogram is a named block of code that does a specific job. They make programs modular, easier to read, test, reuse and maintain, and support team development.

Calling a reusable subprogram

Calling a reusable subprogram

Procedures and functions

  • A procedure performs actions but does not return a value to the caller.
  • A function returns a value: RETURN result.
  • Example: FUNCTION area(w, h) RETURN w×h ENDFUNCTION. Call: x = area(3, 4) gives 12.

Parameters and arguments

  • Parameters are variables in the definition (w, h); arguments are values passed when calling (3, 4). Parameters make subprograms flexible.

Definition and call

Definition and callStageExampleMeaningDefinitionsquare(n)n is the parameterCallsquare(5)5 is the argumentCalculationn * n5 * 5Returned result25Value used by caller

Scope

  • Scope describes where a name can be accessed. A local variable or parameter is accessible within its local scope; a global name has wider program scope under this lesson’s model.
  • Scope is different from lifetime. Prefer local variables and explicit parameters to reduce unintended changes to shared state.

Names and scope

Names and scopeNameDeclared inAccessible fromscoreMain / global scopePermitted program scopestotalLocal to addScoresThat local scopenParameter of squareWithin square

Structured programming

  • Use sequence, selection and iteration to organise control flow. Divide a complex solution into focused subprograms with clear interfaces.
  • A main program can call subprograms; those subprograms may call others.

Library routines

  • A library routine is a prewritten reusable subprogram provided by a library; some are built into the language environment.
  • Using a tested routine can save implementation time, but check its parameters, return value and assumptions.

ஸ்லைடுகள்

Sign up free to view the lesson slides

Step through every slide for this topic — plus flashcards and revision notes — with a free account.

பயிற்சி கேள்விகள்

இலவச முன்னோட்டம் — 33-இல் 8 கேள்விகள். அனைத்தையும் பார்க்க பதிவு செய்யவும்.
  1. 1.What is a subprogram?

    Easy
    • Aa named block of code that does a job
    • Ba variable
    • Ca loop
    • Dan input
  2. 2.In a function, what does RETURN followed by an expression do?

    Easy
    • Asends a value back to the caller
    • Bends the program
    • Ccreates a loop
    • Dprints
  3. 3.What is a procedure?

    Easy
    • Aa subprogram that does not return a value
    • Ba subprogram that returns a value
    • Ca variable
    • Da loop
  4. 4.What is a parameter?

    Easy
    • Aa variable in a subprogram definition
    • Ba value passed in
    • Ca loop
    • Da function
  5. 5.What is an argument?

    Easy
    • Aa value passed to a subprogram
    • Ba variable in the definition
    • Can error
    • Da loop
  6. 6.Why use subprograms?

    Easy
    • Ato reuse code and make programs easier to maintain
    • Bto slow programs
    • Cto add errors
    • Dto avoid variables
  7. 7.What is a local variable?

    Easy
    • Aone accessible only within its local scope
    • Bone accessible everywhere
    • Cone that must be constant
    • Done that must control a loop
  8. 8.What is a global variable?

    Easy
    • Aone accessible throughout the program
    • Bone inside a subprogram
    • Cone that never changes
    • Da loop

Unlock all 33 questions & more

இந்த தலைப்பிற்கான ஒவ்வொரு கேள்வியையும், ஸ்லைடுகளையும், ஃப்ளாஷ் கார்டுகளையும் மற்றும் திருப்புதல் குறிப்புகளையும் பார்க்க இலவச கணக்கை உருவாக்கவும்.

முந்தைய தேர்வுகள்

இந்த தலைப்பிற்கான முந்தைய தேர்வு பயிற்சி விரைவில் வருகிறது.
விரைவில் வருகிறது