Lesson 12: User-Defined Functions

Functions are the building blocks of a C/C++ program. A function is a group of statements that together perform a specific task.

Why do we need functions?

  • Functions help us in reducing code redundancy. If functionality is performed at multiple places in software, then rather than writing the same code again and again, we create a function and call it everywhere. This also helps in maintenance as we have to change in one place if we make future changes to the functionality.
  • Functions make code modular. Consider a big file with many lines of code. It becomes easier to read and use the code if the code is divided into functions.
  • Functions provide abstraction. For example, we can use library functions without worrying about their internal work.

 

© 2024 Air Supply Information Center (Air Supply BBS)