Functions in C++ || C++ For Beginners
Video Title: Functions in C++ || C++ For Beginners
Hello everyone in this hello everyone in this video I will explain about functions in C++ if you are learning any new topic in any programming language the first question that should come to your mind is why you are learning this topic what will be the
Use of the that topic think about that I will tell you the use of functions through a small example for example here in this code I am calculating the area of circle I have taken a float variable R which is for storing radius using the user input SE
Function I have I will be storing it in R I have taken another variable area and area equal to 3.14 into R into R which is area of a circle now I will display the area of it see how the code runs if I enter the
Radius five it will it it will be printing as the area for example now if you want to find out area of five circles if you want to find out area of five circles will you rewrite this code for five times will you write this code
For five times no it will be a foolish thing if you write the same code again and again in these kind of situations okay in these kind of situations we will be using functions functions are like we will be writing it once we will just
Write it once we will be using it as many times as we wish we will see how we will be implementing these functions in the code mainly function has three parts in it function has three parts in it the first part is function declaration or it is also known as function prototype second
Part is function definition and third one is function call we will see the syntax of it 1 by by one it is a Syntax for first one function declaration the syntax will be return type return type P what will that function will return return if the function returns as a integer value we
Will be writing here as int if the function returns as a float value you will be writing float if the functions returns nothing then we will be writing here void void means nothing after the written type we are writing the function name here function name and after the
Two brackets and semicolon in the brackets in some functions you will need to pass the arguments here in the bracket I will tell you about the arguments or parameters in the next class in this video I will discuss about functions without the arguments okay simply remember return return type
Function name and then semicolon second one is function definition means the Syntax for function definition is return type function name again brackets and curly braces here in the curly braces you will write the code that you want to execute here definition means what will the function should do what should the
Function do that you will be writing here in the function definition and third is function calling function Syntax for function calling is just write the function name and brackets and semicolon we will see it in the vs code Now for example here suppose imagine we are calculating the area for five circles now how you will write the function for it first thing is function declaration if I think here the function we are writing is returns as nothing so we are writing vo here the function we
Are writing it returns us nothing so I’m writing void here after that function name I’m taking the function name as calculate area simply Cal area and two brackets and semicolon that’s it function declaration is completed here it is function declaration here now I will write the function definition here
After the main function okay it is is the main function this total is main function after the main function I’m writing the definition here same for syntaxes return type and function name and after that calra in the crais you’ll write the code you want to execute here what should the function
Should do just copy this code from here means the function will calculate the area here same code I write written in the main block I have copied here now this calculate area when this is called all this code will be executed if I call it from main function okay Cal area Cal
Area if I write like this first whenever we execute a program the control will go into main function in the main function first line is calculate area means this function will be called all the code which you have written in this function this will execute means when I write
This this code will execute that’s it now see the output once and again I will explain You it is asking the enter radi if I enter the radius area is printing here for example if you calculate want to calculate it for two two circles you’ll just write this code this function you will call this function just one more time that’s it you will
Not rewrite this code you will just call it one more time if I want to if I want for three circles I just call it again for four C I I will again come now see the output See the output here 1 minute I delete This now it is asking me enter radius I enter the radius okay and after that enter radius again four and it is giving me the result here I will write a end to print the answer in next line how many times we called that function that many times this code will
Execute here the code which we written in the uh definition how many times we are calling it that much time this code will execute okay here we should not write it here I’ll write it in the next line see out and now here no need of this
Here I am writing after the function calling I am writing the IND statement here and semicolon here semicolon is Miss now see the output for it contr s control t for running the code here you can see I am entering the radius here for example for it printed
As the answer again 7 radius 9 radius area is 254 and 10 radius 314 is the answer in this way you are just writing the code once here in the definition you are just writing the code once but you are executing is as many times as we
Want functions are in this way the function are very help we will just write it once and we will use it as many times as we wish another important one is you can in the in this functions you can Define and declare it at the same time only means here you are def
Declaring it right here only you can Define it okay above the main function above the main function you can declare it here only I’ll just copy and P a code there sometimes if you want if you you want then you can write this declaration and definition at the same place only
Here the function is not declared just to defined here but if it is above main function it is correct only it will perform the same task here also like that it will give us the same same output so functions are very important topic I have made a lot of effort in
Putting the video uh if you like the video please like share and subscribe it
Video Keywords: C++, c++,cpp,program,programming,beginners,for,software,devloper,devlopment,coding,coder,functions,definition,declaration,prototype,callung,int,float,sum,area,of,circle,radius
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99