Programming Functions and why are they so special

823 views

I’m still trying to wrap my ahead around this concept.

I’ve done basic maths, so I know that f(x) = x is like a function, but I can’t find an intuitive way of explaining why some functions don’t have to return values. In addition, what separates functions from just lines of code?

In: Technology

12 Answers

Anonymous 0 Comments

A void function (one that does not return a value) can be seen as a programmed routine. Most of the time, these functions are used to call other functions or to create/destroy global variables.

Anonymous 0 Comments

You use functions to break up the code into pieces. Each function should perform one task, if it’s more than that, it can be broken up into even more functions (that’s sort of what abstraction is).

Some functions may need to return a value, but some may not at all. If you have a function that just deletes a file, you don’t need to return anything from it. But if you have a function that adds two numbers, you need to return the result.