Can u explain me what are functions? In simple words. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Can u explain me what are functions? In simple words.

27th Dec 2016, 1:29 PM
mahesh naandade
mahesh naandade - avatar
26 Answers
+ 24
Good day. I can explain it to you in two ways (how I came to it): 1. Real life; 2. Coding. 1. In real life a "function" is what some object can do, I mean capable of doing. A car can horn (horn(), lol), an umbrella can protect you from rain (protect()), a dog can bark (woof()), a cat can meow (meow(), sometimes at night, that annoys you, right? ^^). 2. In coding it's all the same. Imagine you created an object and gave this object an ability to summarize two integers: a and b. So the function will be sum of a and b, sum = a+b. And then return it. So you actually created an object with a sum function and you may use it for future objects. Hope it helps.
27th Dec 2016, 1:33 PM
Ivan Karev (RagingFireGaming)
Ivan Karev (RagingFireGaming) - avatar
+ 18
A (named) piece of code that gets executed when called.
27th Dec 2016, 1:31 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 12
A function is a block of codes written for a specific task. example: int main( ) notice this '( )', it usually signifies a function, like scanf( ), printf( ), these are functions.
27th Dec 2016, 1:33 PM
Saumya
Saumya - avatar
+ 12
A magic box that takes input and produces output..... As a user you need not worry how its implemented. You just need to make complete use of it.
28th Dec 2016, 4:12 PM
kars
kars - avatar
+ 8
set of instructions
31st Dec 2016, 6:01 AM
kajal tiwary
kajal tiwary - avatar
+ 7
In very simple terms, you can think of a function as a machine. You provide some input to the machine, then it acts on the input, and finally gives you the output. For example the juicer machine. You insert oranges, it then acts on the input( Orange ), and gives you output(juice). input orange; output = juice(orange) Programming is very easy of you visualize it!
28th Dec 2016, 8:54 AM
Siraj Qazi
Siraj Qazi - avatar
+ 6
yes it helped me . thanks
27th Dec 2016, 1:35 PM
mahesh naandade
mahesh naandade - avatar
+ 4
give input, get output
31st Dec 2016, 9:12 AM
Aref Davari
Aref Davari - avatar
+ 3
function is nothing but a small pieces of code..(set of instructions)Which when needed can we use several times..!!..
14th Jan 2017, 12:35 PM
Diksha Chourasiya
Diksha Chourasiya - avatar
+ 3
A function is a block of code (instructions) that work together to perform a specific task. Functions allow the the programmer to define a task only once and give separate parts of the program access to it. This software reusability helps avoid writing and repeating code over and over again. Plus it reduces the size of the program by writing a function(block of code) once , instead of writing the same code over and over again. This saves time and money.
9th Nov 2017, 5:01 AM
Rick Zalman
+ 2
Function is a set of instructions. It is used to perform specific operation. There are two types of functions, i) Predefined function, (The function that is present already) eg: cout (its operation is to display output) ii) User-defined function. (The function that we define) eg: add() (a simple function to add two numbers)
31st Dec 2016, 2:52 AM
Nihal Sheik
Nihal Sheik - avatar
+ 2
function is a set of code that you use often in your code For ex. you have a program for calculating n!/r! where ! means factorial like 4!=4*3*2*1 here you can write function to calculate factorial and can use that for calculating factorial of n and r
31st Dec 2016, 4:16 AM
shashank
+ 2
well a function is basically some kind of a tool which when you give it a specific data/inputs it do some certain task you specified , say I created a function to multiply some number with another number and to give me back / return , the value of the multiplication , so let call that function : 1. func int adder(int x,int y){ 2. int z = x*y; 3. return z; } so in here in line one , the first is what type of data we want this function to return after executing/calling this function and the adder is the name of the function and what is between the brackets is the 2 numbers we are multiplying / our input data . so now after calling this function in the main function we will just call it by its name and with the data we want to multiply it , and we save the returning value in an integer to keep it
31st Dec 2016, 6:10 AM
Moustafa Mahmoud
Moustafa Mahmoud - avatar
+ 2
function is just a symbol that indicating there have potential code and it will be expanding while you running this program
31st Dec 2016, 6:41 AM
Lazarus
Lazarus - avatar
+ 2
Hey! New to the app but not too new to programming, at your service! A function is just a name, given to a group of statements that *do* something. Let me explain... If there is a certain task, or certain element to your program that is used very frequently, it would be very painful to write out that same code every time you wanted the program to do it. So to save space and time, you define it once and give it a name (make the FUNCTION) and just *call* it everytime you want to use it! In short functions are a way to modularize your work into discreet tasks/elements, to keep your program organized and readable!
31st Dec 2016, 6:58 AM
Noah P
Noah P - avatar
+ 2
A group of statements that together perform a task.
31st Dec 2016, 12:39 PM
Priyanshi
Priyanshi - avatar
+ 1
functions are like simple machines in the programming world. They basically get specific tasks done.
31st Dec 2016, 4:28 AM
koki Christopher Titewondze
koki Christopher Titewondze - avatar
+ 1
5
31st Dec 2016, 7:44 AM
Bala
+ 1
Functions are building blocks of the programs. They make the programs more modular and easy to read and manage. 
31st Dec 2016, 12:42 PM
Priyanshi
Priyanshi - avatar
+ 1
Given any function and its arguments (Language dependent) after some instructions there will be a result. For instance in mathmatics one dimensional variable y=f(x)=x*x (x squared), the return of the function f is the square of variable or argument x.
31st Dec 2016, 4:53 PM
Christyan Condé
Christyan Condé - avatar