What is a function. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is a function.

23rd Jun 2019, 1:35 PM
Abhyodaya Dubey
2 Answers
+ 2
As Bhavya Bhav already gave you an idea what it is I will provide you an example why we need functions(this just one use case) Take this code int result = 2*2+3; print(result) ; int result = 3*3+5; print(result) ; int result = 8*8+3; print(result) ; As you can see same code is repeated for different values We can use a function to avoid this void func(int x, int y) { int result = x*x+y; print(result) ; } func(2, 3); func(3, 5); func(8, 3); As you can see using a function addresses code repition and make code more readable
23rd Jun 2019, 2:28 PM
Ias0601
Ias0601 - avatar
+ 1
Thanks a lot
24th Jun 2019, 8:33 PM
Abhyodaya Dubey