I m an 11th std student and 14 years old this is my first post and i want your help for understanding functions in C++
can u help?![]()
|
I m an 11th std student and 14 years old this is my first post and i want your help for understanding functions in C++
can u help?![]()
Do you mean functions in general?
It is just a piece of code which is given a name and can operate on data and return a result. For example:
That is a simple function called "add" that adds two numbers and then returns the result. You can call it like this:Code:int add(int a, int b) { int sum; sum = a + b; return sum; }
After that, x will have the value 14.Code:int x; x = add(4, 10);
There are lots of pre-defined libraries of functions to do things like arithmetic, string manipulation, file i/o, etc.
Is that the sort of thing you want to know?
yep so can u give my more please![]()
More what?
Functions? See here: C library - C++ Reference
Or more explanation of how functions work? See here: http://www.cplusplus.com/doc/tutorial/functions/
What do you want to know?
any possible thing about the functions
but that functions are a bit more higher level![]()
What exactly do you want to know that the links provided, Wikipedia, reference books, etc. don't tell you?
One could write an entire book on the concept and implementation of functions. And several books on the libraries of functions available. I am not going to do that without getting paid.
What I told my students was that functions answer a single question. For example "what is the sum of a and b?" Or "What is the average of this list of values?"
But yeah, this is a discussion forum and not a class room, so you're not going to get a good answer to such a general question. You can ask as many specific questions as you want though, but it might take some time to go through them all (and you'll get the best answers if you ask them one or two at a time).
i know a bit of function but i know c++
can you please repeat all the questions ?![]()
they are used in C++ programs and contains a bracit and are outside of main
They are useful for Structured programming:
- They break the program up into manageable and (hopefully) independent chunks of code.
- They break the function of the program into manageable units.
- They simplify testing, because you can test each function before you have written the entire program
- They avoid duplication of code. For example, if you want to calculate the average of a set of numbers, you could duplicate the code to do that in each place, but if you put it in a function then you only have to write it once.
- Because of this, they reduce errors.
- They allow for re-use (for example all the standard libraries mean that you don't have to write code to calculate sine or square root whenever you need it)
- They allow for efficiency: the standard math functions, for example can be written using very advanced "tricks" that the average programmer may not know, they might also be optimised for the specific target processor.
- Other things I haven't thought of ...
Subroutine - Wikipedia, the free encyclopedia
« Help please! | What happens when a black out happens, and computer and it is in the middle of doing something? » |