0

User defined functions

Is it better to use user defined functions in C++ more often than writing programs without them...if so, what are its benefits?

21st Jan 2019, 10:22 AM
Zeus Soter
3 odpowiedzi
+ 3
Functions make your code shorter. It can devide your code into some different part, make your code clear. If there are some problems, you can only modify your function, dont need to change the structure of your code👌
21st Jan 2019, 11:19 AM
LetterC67
LetterC67 - avatar
+ 2
Just extending into these answers with an example. Imagine writing that 50 lines of code every time you need to calculate that particular thing instead of defining it as a function and just calling it with a f().
21st Jan 2019, 12:01 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
1.) You can reuse the function, whenever you need it again in your program; 2.) in allows you to structure your code, like chapters in a book, one for each topic, making it easier to read; 3.) each function has it's own names (variables and functions), so you can use whichever name you like and don't have to fear it messes with your other code somewhere.
21st Jan 2019, 11:17 AM
HonFu
HonFu - avatar