COP3014 functions
Three ways to define functions:
1. put the function on top of main 2. put the function signature in front of main 3. same as 2 just do not provide variable names. Makes code hard to read. Do not use.
What is a argument of the function?
A argument of the function is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters or Arguments are optional; that is, a function may contain no arguments or parameters.
What is a function declaration?
A function declaration tells the compiler about a function name and how to call the function. The actual body of the function can be defined separately.
When is a function declaration required?
Function declaration is required when you define a function in one source file and you call that function in another file.
When should you declare the function?
In such case, you should declare the function at the top of the file calling the function.
What does a function declaration do?
It tells the compiler about a function's name, return type , and arguments(parameters).
What is a Function Body?
The function body contains a collection of statements that define what the function does.
How do you call a function?
To call a function, you simply need to pass the required parameters along with the function name, and if the function returns a value, then you can store the returned value.
Explain when a program calls a function:
When a program calls a function, the program control is transferred to the called function. A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program.
What does it mean to call a function?
While creating a C function, you give a definition of what the function has to do. To use a function, you will have to call that function to perform the defined task.
When you sum an array, what is the main difference between a character array or a string and a regular array of integers?
With a string it gives us a NULL, it gives us the length of a string. Every time we use a string, we know its length.
arugment(parameter} names are not important in function declaration only their type is required, so the following is also a valid declaration:
int max(int, int);
What is a function?
is a group of statements that together perform a task.
What is a return type?
is the data type of the value the function returns. some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.
What does function strcat() do?
it concatenates two strings
What is a function definition provide?
it provides the actual body of the function.
If you pass an array to a function, you need to pass _____
its length with it.
What keyword do you use for a function that performs the desired operations without returning a value?
keyword is void
If you pass a string to a function, you _______ the length, it is when you ______.
know the length, it is when you hit the NULL character.
Every C program has at least one function, which is_____.
main()
C standard library provides _____ built-in functions that your program can call.
numerous
a function definition in C programming consist of ________ and a ______
of a function header and a function body
A function declaration has the following parts :
return_type function_name( argument or parameter list );
The general form of a function is:
return_type function_name(arguments or parameters ) { body of the function }
What is a function name?
this is the actual name of the function. The function name and the parameter list together constitute the function signature.