Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COP2220 ŠI Handout Week of 9182017 Cole Hirapara and Leo Herrera What are the th

ID: 3607570 • Letter: C

Question

COP2220 ŠI Handout Week of 9182017 Cole Hirapara and Leo Herrera What are the three parts of a user-defined function? 2 When shouid you write a user-defined function? 3 What is a library function? 4. How do you call a function with a. No input and no outpu b. Input, but no ouput G. No input, but output d. Input and output Wite a function call to the void function "add that takes two integers 6. What does the data type in front of functions mean? 7. For the definition of functions that have no parameters, what do you write? &. How would you save the result of an integer function "subtract into a predefined variable

Explanation / Answer

Hi,

I have answered few for which i have knowledge on. Thanks :)

1.C allows you to define functions according to your need. These functions are known as user-defined functions.

Function prototype
A function prototype is simply the declaration of a function that specifies function's name, parameters and return type. It doesn't contain function body.

A function prototype gives information to the compiler that the function may later be used in the program.

Syntax of function prototype
returnType functionName(type1 argument1, type2 argument2,...);

The function prototype is not needed if the user-defined function is defined before the main() function.


Calling a function
Control of the program is transferred to the user-defined function by calling it.

Syntax of function call
functionName(argument1, argument2, ...);

Function definition
Function definition contains the block of code to perform a specific task i.e. in this case, adding two numbers and returning it.

Syntax of function definition
returnType functionName(type1 argument1, type2 argument2, ...)
{
//body of the function
}
When a function is called, the control of the program is transferred to the function definition. And, the compiler starts executing the codes inside the body of a function.

Passing arguments to a function
In programming, argument refers to the variable passed to the function. In the above example, two variables n1 and n2 are passed during function call.

The type of arguments passed to a function and the formal parameters must match, otherwise the compiler throws error.

If n1 is of char type, a also should be of char type. If n2 is of float type, variable b also should be of float type.

A function can also be called without passing an argument.

Return Statement
The return statement terminates the execution of a function and returns a value to the calling function. The program control is transferred to the calling function after return statement.

Syntax of return statement
return (expression);

The type of value returned from the function and the return type specified in function prototype and function definition must match.

2. C allows you to define functions according to your need. These functions are known as user-defined functions.

3.The C library functions are provided by the system and stored in the library. The C library function is also called inbuilt function in C programming.
In order to use Inbuilt Function in C, you must include their respective header files, which contain prototypes and data definitions of the function.

6. The data type in front of function actually means the type of data the function will return after the execution of the statements in it.

For ex: int functionname() states that the function is of type Integer and returns an integer.

10. Top Down design is the process of designing a solution to a problem by systematically breaking the problem into smaller, more manageable parts.

11.The precondition statement indicates what must be true before the function is called.
12. The postcondition statement indicates what will be true when the function finishes its work.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote