Answer:
1) A function definition consists of the function declaration alongwith the body of the function inside the brackets.
Example:
int fun(int a, int b)
{
return a+b;
}
2) The parameters of a function are the variables written inside the brackets beside the name of the function and the values of the parameters are passed when the function is called.
In this, a and b variables are the parameters of the function in BOLD
int fun(int a, int b)
{
return a+b;
}
3) The return type of the function is the first thing written in the definition of the function which tells us aout what type of data the function will return.
In this case, int is the return type
int fun(int a, int b)
{
return a+b;
}
4) Yes, when the function which returns a value is called, a variable should be taken on the left side which collects the returned value.
Example:
If the function is :
int fun(int a, int b)
{
return a+b;
}
Call should be like this:
int c = fun(1, 2);
5) A function is called by writing its name along with the round bracket pair. If parameters are to be passed, values are written inside the brackets.
Example:
Example:
If the function is :
int fun(int a, int b)
{
return a+b;
}
Call should be like this:
int c = fun(1, 2);
6) The same way we called in the last example:
The return type is int
SO, we are calling by first declaring a variable or doing it in the same line.
Example:
If the function is :
int fun(int a, int b)
{
return a+b;
}
Call should be like this:
int c = fun(1, 2);
OR
int c;
c= fun(1,2);
7) The function which has a return type of void can be called directly without the need of any collection of return value:
Example:
If the function is :
void fun(int a, int b)
{
cout<<a+b;
}
Call should be like this:
fun(1, 2);
8) Yes, the parameters are passed during the function call, either directly value can be passed or a variable containing a value can be passed.
Example:
If the function is :
int fun(int a, int b)
{
return a+b;
}
Call should be like this and a and b are the parameters passed:
int a=1, b=2;
int c = fun(a, b);
9) We put function declaration at the top of int main() so that when we call the function inside the int main, the compiler can identify the name of the function as it is declared above. Due to the top down approach of the compiler, we need to do so.
10) We put all the definitions after main because declarations are enough to avoid a runtime error which are written before the main function.
11) When we write a function in the subclass which is having exactly same name, parameters and return type as a function in the superclass, then it is referred to as method overriding.
12) When two functions with same name but different number of parameters or order of parameters or type of parameters are delcared in a class, then it is called function overloading.
13) & symbol is the address-of operator which returns the address of any variable inside memory with which it is used.
14) When we use const inside the function parameters, it means that the function is not allowed to change the value of the parameter.
15) By looking at the function header, we can deduce about its return type, and what can we pass as the parameter to the function, but the functionality of the function can only be deduced by using the body of the function.
16) Yes, i know that we can call a function inside another function. As main() is also a function and we generally call functions inside main, so we can also call them inside any other function.
17) Yes, we can call the same function more than once. Infact, there is a problem solving technique called recursion which depends on the same phenomenon of calling one function more than once with different values.
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
definition contains the statements that make up the function. definition contains the statements that make up...
In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an array (allocated off of the heap in the function) containing only the elements of array a that pass the “test” t. The function iterates through all the elements of a, and constructs a new array containing all the elements that pass the test. When the parameter corresponding to “size” is passed in (by reference), it contains the size of the array a. In the...
A function contains the statements that make up the function. prototype
write the function definition
call the function from main and make sure it works as
required.
13. DA void function named CapLock() that takes a char reference parameter. If the parameter is a letter. the function will assign the parameter its opposite case (uppercase becomes lowercase and vica versa); otherwise, it will do nothing. 14. double function named Minimum) that takes four double parameters. It returns the minimum value of the parameters.
in C++ and also each function has its own main function so
please do the main function as well. Previously when i asked the
question the person only did the function and didn't do the main
function so please help me do it.
1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...
1. In a function that gets a value from the keyboard and communicates that value to the main function via a parameter, the parameter used is considered __________. 2. In a function that receives a value from the main function via a parameter and then displays the parameter value on the screen, that parameter is considered __________. 3. In a function that receives one parameter value from the main program and passes back a changed value of the parameter, that...
1. Write a statement that calls a function named showSquare, passing the value 10 as an argument. 2. Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int data type and areturn type of void. 3. Write the function prototype for a function called showScoreswith a parameter list containing four integer variables and a return type of void. 4. Look at the following function definition: double getGrossPay(int hoursWorked, double payRate)...
Match the definition with the vocabulary word that best fits the definition. The library used for formatting output. The location of a variable in memory The library used to read and write to files Data that is passed back to the calling function as the function ends. When an argument is passed to a function this way, a copy of the argument (or of the value stored in the argument variable) is copied into a function parameter variable. A statement...
Problem 1 1. Consider the following function (K is the size of array A and L is the size of array B) bool func (int A[], int K, int B[], int L, int start) { if (L > K-start) return false; for (int i =0; i < L; i++) { if(A[start+i] != B[i]) return false } return true; } What are the input and output variables to this function. Trace it for the following call: int F[] = {1, 3,...
What is wrong with the following function definition? void fill(const int a[], int size) { for (int i = 0; i < size; i++) { a[i] = 0; } return; } Answers: The function cannot change the array parameter. The array should be passed as a call-by-reference, not call-by-value. The for loop causes an out-of-bounds indexing error. Nothing, the code works fine as is.
C++ LAB 19 Construct functionality to create a simple ToDolist. Conceptually the ToDo list uses a structure called MyToDo to hold information about each todo item. The members of the MyToDo struct are description, due date, and priority. Each of these items will be stored in an array called ToDoList. The definition for the MyToDo struct should be placed in the header file called ToDo.h Visually think of the ToDoList like this: There are two ways to add items to...