answersLogoWhite

0


Best Answer

Functions are used to reduce the lines of code and the complexity of the code. For an instance let us suppose that you want to calculate the factorial of numbers at different times in a program. There are two ways to do this

1. Write a 4-5 line code every time you want to calculate factorial.

2. Write a function of 4-5 lines which calculates the factorial and call that function every time you need to calculate factorial by just writing a single line.

In C++ you can pass the variable, address of the variable or a reference to the variable in a function

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the benefit of using function.llustrate different ways of passing argument to function in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the benefit of using standard c language functions over windows API function?

Portability.


What is the difference between inlinefunction and function overloading?

The normal way a function works is that whenever your code encounters a call to the function, it jumps to the body of the function code. An inline function tells the compiler that it should actually copy over the code from a function body into all places where that function is called. In some cases this can cause a dramatic reduction in run time, but in others it causes nothing more than increasing the size of the produced executable. Function overloading refers to the ability to have multiple functions with the same name, but different parameter types.


What is outline function in c plus plus language?

Outline is the opposite of inline. An inline expanded function is any function or class method where the declaration also provides the definition (the implementation). This is known as implicit inline expansion. Where the definition is kept separate from the declaration, you may use the inline keyword to specifiy that the function should be inline. This is known as explicit inline expansion. Inline expanded functions (whether implied or explicit) does NOT mean the function will in fact be inline expanded. It is merely a suggestion to the compiler. If the compiler's optimisers determine that there is no advantage to be gained by inline expanding a particular function, then that function becomes an outline function. Inline expansion simply means that the body of the function is inserted in place of the function call. Function calls are expensive in terms of memory and performance, so by eliminating the function call completely, your code performs faster and uses less memory. However, functions that are called many times throughout your code will result in a much larger code size, and large code runs slower than small code. Thus the benefit of eliminating a function call has to be weighed against the increased code size. Although some compilers do allow you to override the compiler's inline expansion optimisers, this is strictly non-standard. The best judge of what to expand and what not to expand is best left in the hands of the compiler, and indiscriminate use of the inline keyword should generally be avoided.


What is a function prototype in C and C plus plus?

A function prototype is basically a definition for a function. It is structured in the same way that a normal function is structured, except instead of containing code, the prototype ends in a semicolon.Normally, the C compiler will make a single pass over each file you compile. If it encounters a call to a function that it has not yet been defined, the compiler has no idea what to do and throws an error. This can be solved in one of two ways.The first is to restructure your program so that all functions appear only before they are called in another function.The second solution is to write a function prototype at the beginning of the file. This will ensure that the C compiler reads and processes the function definition before there's a chance that the function will be called.For example, let's take a look at a few functions form a linked list implementation.// Sample structuresstruct linked_list_node {int data;struct linked_list_node *next;};struct linked_list {int size;struct linked_list_node *root;};// Function Prototypesvoid deleteLinkedList(struct linked_list *list);void deleteNodes(struct linked_list_node *node);// Actual functions:// deletes the given linked listvoid deleteLinkedList(struct linked_list *list) {if( list != NULL ) {// delete nodesdeleteNodes(list->root);// lose the pointerlist->root = NULL;// delete actual listfree(list);}}// deletes all nodes starting at nodevoid deleteNodes(struct linked_list_node *node) {if( node != NULL ) {// deallocate next, if it existsif( node->next != NULL ) {deleteNodes(node->next);// lose the pointernode->next = NULL;}// deallocate nodefree(node);}}


How far can poorer countries benefit from scientific technology?

Poor countries can benefit from a limited amount of scientific technology. They do not have the resources to utilize higher levels of technology, but they can benefit from things that improve the quality of food production, health care, and sanitation.

Related questions

When does marginal benefit occur?

Marginal benefit 'occurs' for any benefit (price) function, since a marginal term is simply the first-order derivative of its parent function. Marginal benefit is strictly greater than zero only when a benefit function is always increasing in total benefit over its domain.


What is the best example of a situation that would benefit from a written argument?

A situation that would benefit from a written argument is when presenting a case in a court of law, where a well-structured and persuasive written argument can help support legal reasoning and advocate for a particular outcome effectively. The clarity and organization of a written argument can also be beneficial in academic settings, such as when writing research papers or essays to defend a thesis or hypothesis.


Charles beard argument against the Framers?

he claimed that the Framers were rich people who wrote the Constitution to benefit themselves


What type of argument is It might be true that society as a whole would benefit by having some group discriminated against?

Utilitarian


What is an example of counter argument?

one man says that brick is red and the other says no its more Burgundy when it is really was red


Can you give five reasons why countries engage in international trade?

1. They each produce different crops and benefit from the trade of these. 2. They each produce different fruits and benefit from the trade of these. 3. They each produce different types of cars and benefit from the trade of these. 4. They each produce different styles of clothes and shoes and benefit from trading these. 5. They each produce different weaponse and perceive benefit from trading these.


What is most likely to produce a biased source?

B. The sources creator could personally benefit from convincing people to accept his argument.


How do proteins benefit humans?

Almost every single cellular function we do is performed by proteins.


Do capitalist agree that it might be true that society as a whole would benefit by having some group discriminated against is an argument for discrimination?

No Utilitarians do.


What is the benefit of working in China?

One benefit to working in China is the fact that you will be submerged in a different culture. Another benefit is the fact that you can learn a lot of different business practices that you may not be exposed to in your home country.


What is the sentence of benefit?

Do you believe President O'Bama's health care plan will benefit the country? We benefit from donating money to charity because we receive an income tax deduction. Do you think my daughter would benefit from the summer school program? One benefit that company offers is a four week vacation for all employees. Who stands to benefit from a change in the law? For Mom's benefit, please don't start an argument on Easter Sunday. The budget increases will benefit every school district in the country.


What is the function of the root of a banana?

to absorb nutrients for the benefit of the plant and its fruits as well as to provide anchorage