+ 1
What is a function.
3 ответов
+ 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
+ 1
Thanks a lot