Functions Flashcards

1
Q

What is a function in C?

A

A named, independent section of C code that performs a specific task and optionally returns a value to the calling statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two types of functions in C?

A
  • Standard Library functions (built-in)
  • User-defined functions (custom)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the syntax for creating a function in C?

A

[data_type] function_name([data_type param,…]){ data_type local_variable; … program_statement; … [return expression;]}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the function prototype declaration tell the compiler?

A
  • Its data type
  • Its name
  • The argument it takes
  • Who can call it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What keyword is used to return a value from a function?

A

return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the default data type of a function if omitted?

A

int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does ‘call by value’ mean?

A

Each argument passed to a function is evaluated, and its value is passed into the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is ‘call by reference’?

A

A method where a reference to the variable (memory address) is passed into the function instead of its value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are non-returning functions without parameters?

A

Functions declared as void that do not return a value and do not take any parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a returning function with parameters?

A

A function that returns a value and accepts parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Fill in the blank: The function’s _______ is a unique identifier used to call it.

A

name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the purpose of the standard library functions in C?

A

They are built-in functions defined in header files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False: A function can be called from within another function.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the role of the return statement in a function?

A

It indicates that the function is to return the value of the expression back to the calling function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What must the function prototype declaration reflect?

A

The data type of the return value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the function ‘double_it’ do in the provided example?

A

It doubles the input value a specified number of times and prints the result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a user-defined function?

A

A function created by the user to meet specific needs in the program.

18
Q

What is the syntax for non-returning functions with parameters?

A

void function_name(data_type param1,…){ statement1; statement2; … }

19
Q

What is the output of the function ‘hello_world’ that accepts an integer parameter?

A

It prints ‘Hello World!’ and the value of the parameter.

20
Q

What is the significance of the ‘&’ symbol in a function call?

A

It is used to pass the address of a variable (for call by reference).

21
Q

What happens when a function is called with parameters that are not the same name as the corresponding parameters?

A

It is valid, as it is the variable’s value that is being passed, not its name.

22
Q

What is the result of the function ‘divide’ in the example?

A

It returns the result of dividing two integers as a float.

23
Q

What is the syntax for a returning function without parameters?

A

data_type function_name() { statement1; statement2; return expression; }

24
Q

What is the purpose of the function getInteger()?

A

To prompt the user for an integer value and return it.

25
What is the output when the user enters the integer value 4 in the getInteger() function?
The value of number is 4
26
What is the syntax for a returning function with parameters?
data_type function_name(data_type param1,...) { statement1; statement2; return expression; }
27
What does the computeAverage function do?
Calculates the average of three grades (math, science, english).
28
What is the output of the computeAverage function when grades are 90, 85, and 98?
Average grade is 91.00
29
What is the scope of function variables?
Local variables can only be accessed within the function where they are defined.
30
In the inner block of a function, how is a variable name treated if redefined?
The inner block variable hides the outer block variable.
31
What is the output of the outer block's variable a if it is defined as 1 and inner block redefines it as 5?
outer block a: 1
32
True or False: A function's local variables can be accessed by other functions.
False
33
What are local variables also referred to as?
Internal variables
34
What are global variables?
Variables declared outside of any function block, accessible by any function.
35
What is the output of the global variable a if it is defined as 3?
main a: 3
36
What is recursion in programming?
The process of calling a function within itself.
37
What is an advantage of using recursion over iterative statements?
The code stays simpler and shorter.
38
What is the output of the sumOf function when called with the value 5?
Result: 15
39
Fill in the blank: The process of calling a function inside the same function is called ______.
recursion
40
What caution should be taken when using recursion?
It can lead to a program that never terminates.