Functions and parameters flashcards

Learn about functions and parameters in programming with these flashcards and quizzes.

MayaThomas89·21 Karteikarten·15 Fragen
high schoolcomputer_scienceprogramming
0
Gewusst
1 / 21
0
Lerne noch
Vorderseite

What is a function?

Tippen zum Umdrehen
Rückseite

A block of code that performs a specific task.

Tippen zum Umdrehen
Gewusst
Lerne noch

Quiz(15 Fragen)

Frage 1 von 15

1. What is the purpose of a function?

Begriffe in diesem Lernset(21)

What is a function?

A block of code that performs a specific task.

Define parameters.

Variables used to pass information into functions.

Difference between arguments and parameters?

Parameters are placeholders; arguments are actual values passed.

True or false: Functions can return values.

True, because functions can send back results to the caller.

What is a return statement?

Used to end a function and send a value back to its caller.

Fill in the blank: A function must be ______ before it can be called.

defined

What are local variables?

Variables defined within a function, inaccessible outside of it.

True or false: Functions can modify global variables.

True, if declared global inside the function.

What is a function signature?

The combination of a function's name and its parameters.

Define a void function.

A function that does not return a value.

Question: Can a function call itself?

Yes, this is known as recursion.

Difference between built-in and user-defined functions?

Built-in functions are provided by the programming language; user-defined are created by developers.

Give an example of a function call.

myFunction(arg1, arg2);

True or false: Functions can take multiple parameters.

True, functions can accept as many parameters as needed.

What is scope in programming?

The context in which variables can be accessed.

What does it mean to 'call' a function?

To execute the code contained within the function.

Fill in the blank: A function can be called ______ times.

multiple

What do you use to define a function in Python?

The 'def' keyword.

What is an anonymous function?

A function that is defined without a name, often used for short tasks.

How to pass default parameters?

By assigning a default value in the function definition.

True or false: Parameters can have different types.

True, parameters can be of various data types.

Fragen in diesem Lernset(15)

1. What is the purpose of a function?

A.To perform a task
B.To store data
C.To create loops
D.To manage memory

2. Which of the following is NOT a type of function?

A.Recursive
B.Lambda
C.Global
D.Void

3. What keyword is used to define a function in JavaScript?

A.function
B.define
C.method
D.create

4. What does a return statement do?

A.Ends the program
B.Returns a value
C.Calls another function
D.Defines a variable

5. What is the scope of a local variable?

A.Global
B.Local
C.Public
D.Private

6. Which of the following describes recursion?

A.A loop
B.A self-calling function
C.A variable scope
D.An error type

7. What will happen if a function has no return statement?

A.It won't work
B.Returns None
C.Throws an error
D.Infinite loop

8. What are default parameters?

A.Parameters with fixed values
B.Parameters that can be omitted
C.Parameters that are always required
D.Parameters with multiple types

9. What is a common use of lambda functions?

A.Data storage
B.Short tasks
C.Error handling
D.Loop formation

10. Which statement about parameters is correct?

A.They don't need values
B.They are always optional
C.They can be of any type
D.They can't be changed

11. What happens if you try to use a local variable outside its function?

A.It works
B.It causes an error
C.It returns None
D.The variable is global

12. How can you modify a global variable inside a function?

A.By declaring it again
B.Using 'global' keyword
C.Using return
D.It can't be modified

13. What is an argument in the context of functions?

A.A type of loop
B.A parameter name
C.A value passed to a function
D.An error message

14. Which of the following is a benefit of using functions?

A.Increased complexity
B.Code reusability
C.Single-use code
D.Increased runtime

15. What will happen if you skip giving an argument for a parameter with no default value?

A.The program crashes
B.The function runs without it
C.It defaults to None
D.It throws an error

Ähnliche Lernsets

Eigenes Lernset erstellen

Lade ein PDF hoch, füge Notizen ein oder beschreibe ein Thema – KI erstellt Karteikarten, Quizze und mehr in Sekunden.