Functions in c++

In this article, we shall discuss what a function is and why we need functions in a program.

FUNCTIONS:-
We should avoid large programs as it is difficult to manage a single list of institutions. So, a large program is broken down into smaller units called functions.

A good programmer writes programs that consist of many of these small functions. A large program written with numerous functions is easier to maintain, update and debug than a very long program.

Each function has its own name. When that name is encountered in a program, that function is executed at that time. And when the execution of the function is over, execution returns back to the calling code.
Functions are the building blocks of C++ and the place where all program activity occurs. They are one of C++'s most important features.

TYPES OF FUNCTIONS:-
In C++, there are two types of functions :
1. Built-in functions
2. User-defined functions

1. Built-in functions (or library functions): These functions are part of a standard library made available by the compiler. For example, exit(), sqrt(), pow(), etc. are library functions (or built-in functions).

2. User-defined functions: The user-defined functions are created by you (the programmer). These functions are created as per the requirements of the program.

The syntax of a function,

return_type function_name(type variable_name){
    /* Function declaration */
}


For example, Find the max number between two integers first program we do without using function and the second one is using function.

Without using Function,
#include<iostream>
using namespace std;
int main(){
    int num1=4,num2=5,max_Number;
    if(num1>num2) max_Number=num1;
    else max_Number=num2;
    cout<<max_Number;
    return 0;
}
Output,
5

Using Function,
#include<iostream>
using namespace std;
int max(int num1,int num2){
    int max_Number;
    if(num1>num2) max_Number=num1;
    else max_Number=num2;
    return max_Number;
}
int main(){
    cout<<"\n"<<max(4,5);
    return 0;
}
Output,
5

//------------------------------Bonus for You------------------------------//

How to become a successful YouTuber?

If you want to become a successful youtube in your life so you have to know everything about youtube like how SEO works, how to rank your video on youtube, how to get more traffic, and so on. But for beginners, it is complicated to rank your video on youtube, to get traffic on your youtube channel, and more. So don't worry about it. if you want to become a YouTuber we can help you. Click here and buy the youtube manifest program at an affordable price. This program helps you to become a successful YouTuber and the result of this program was very good.



Post a Comment

0 Comments