How to make a program using function?? And what is the difference btw in main and function. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to make a program using function?? And what is the difference btw in main and function.

5th Nov 2016, 5:13 PM
saijal sinha
saijal sinha - avatar
3 Answers
+ 1
A main function is the heart of your application, you need it to tun your application, but other functions aren't necessary. you use functions for the following reasons: * you need the code multiple times (to avoid code repetition) * you can make your returns so that you can easily get a certain number.
5th Nov 2016, 5:22 PM
somestuffontheinternet
somestuffontheinternet - avatar
0
but how I write a program using function ??? can u give an example...
5th Nov 2016, 5:54 PM
saijal sinha
saijal sinha - avatar
0
int main() { if(greaterThan(2, 1)) { std::cout << "hi" << endl; } return 0; } boolean greaterThan(int x, int y) { return x > y; } so now it would say hi, this is because the function elevates to true
5th Nov 2016, 6:14 PM
somestuffontheinternet
somestuffontheinternet - avatar