C++ Tutorials- Void Function
HTML-код
- Опубликовано: 28 авг 2024
- In C++, like in many other programming languages, you can group functions into two categories:
Those that have a return value and those that do not have a return value.
Functions that do not have a return value are often referred as a void functions. Void functions have the following structure
graspery.com/c/...
Very well made man, by far the best explanation video i’ve seen for c++ haha a bunch of garbage out there! ❤️
Thanks, I appreciate that!
@@YunusKulyyev commenting from year 2020 , and I agree your explanation is good.
@adam: damn right!!!
This Channel is definitely one of my top favourite C++ tutorial RUclipsr! Very well made.
i know this is probably late but if youre reading this thank you,ive been scavengering online tutorials/articles for hours trying to understand void they werent working until i came across this and i think i finally grasped it.THANKS A LOT
Thank you, I am always happy to hear that it is helpful to others!
I wanted to let you know that thanks to your video I got some informations that I was missing to make my program work, Thank you !
Thanks, glad it worked!
So in essence, the int main function pass the values to print function, and the calculation is done in print function and prints out the values, it does not return any value, like the int function did (which passed the value 16 and 32) and the print function prints and not return the 512 value, and thus it prints only the value without returning any value.
You can implement the following code to check how the void and int works:
//First code
#include
using namespace std;
int calc(int i) {
return i * i;
}
int main() {
int i = 2;
int result = calc(i);
cout
Yunus, I'm new to C++ and all programming/coding. Doing homework and was stuck. After re-reading the chapter and professor notes. Still confused. After six damn minutes, you have fixed me on Void Functions. LOL! Should have come to you first. Well played. :)
Hi Eric, love it. Thanks for you rkind words. I am glad that I was able to carry across the idea. Good luck in your programming journey
Thank you for this video tutorial, it was exactly what I needed.
Thank you so much for your good explaination. i was really very much struggling with these stuffs. You videos are so clear to understand, just saved me
You always come up with great stuff. I wish you have more videos
you and bucky are my favorite
Thanks for breaking this down I really get this *Subscribed*
Very well explained. Thanks
new to coding here sorry if i come off ignorant, but i dont really understand. Couldnt you get the same thing by just taking out the void?
Hi John, yeah absolutely but that is not the point. This example is simple example to show how void function works. When you have a complex code, you don't want to have a giant monolithic block of code. Instead, you want to have your code broken down into many separate function each performing a specific task. That way, managing and debugging your code will be much easier.
Can you explain how the computer knows which int in the main function associates with which int in the void prototype seeing as their are called diffrent things
It depends on the order that they are sent. For example when I have void print(int x, int y) and I call this function in my main as print(1,5) the first number will be x and the second number will be y
@@YunusKulyyev ohh that makes sense thank you :)
No problem!
So why does it execute the void function, even though it's not performed within your main function?
Oooh. So void is a function that allows us to create a function executing the stuff we included in the {}?
Void is the name of the type that the function{} returns. Since void means nothingness, it returns nothing
I just started learning C, and the concept of void stopped me cold. I don't understand how you can declare two integers in the main function as rate and hours, but then change them to r and h in the void function and still have the compiler know that int r is the same as int rate and int h is the same as int hour.
It's not the same, void function declares an independent variable called r and assigns the number that was stored in rate. They exist in different memory locations and changing one doesn't affect the other one
Hey , is the fifth row necessary? Because i think that the 15th one does the same job
Hi Xhoni, yes, you can have functions without function prototype, but it has a useful benefits later on
Great explanation so far
Thx that helped me a lot
Salam Yunus.Siz bilen nahili yagdayda habarlasyp bolar?C++ barada biraz komeginiz gerekdi?
Salam Shohrat, men emailyma yazayyn, graspery@gmail.com
nice and slow explanation .. thanks man
Hii! Idk if you're still going to answer but may i know that will there be any difference if we put the int main() under the void functions? Andd if the int main () is below.. will the compiler read from the top to bottom or will it read from the int main() first despite being under some other functions?
A bit confuse on that part but I'll really appreciate if someone could answer it :')
Hi! Yeah, you can place int main() below other functions. Compiler will always read int main () first no matter the position
@@YunusKulyyev Omg thanks mannn!! I need to submit my assignment tomorrow and you've really help me 🙏🏻🥺
bro can you make a video about how void function converting to value returning function? because my teacher ask and I didn't know how thanks bro
good job on intro to functions!! I am currently stuck on making a program using void function which asks the user to enter 3 numbers and the program calculates the sum and average. If you or anyone reading knows a good video or can help out please message me!! thank you
Hey iix, if you have the code, I can check it for you. Or do you have to start from scratch?
Why did u pit void print in the bottom of int main () ?
How about a code that asks you to put a name and age using a function and display a outcome
I have a question please help me
Why we should use void and when
Hello... thank you bro, you did great job, i like your way of explanation :)
thanks, helped a lot
why do you need a function protype ?
leave it to my professor to make it so complicated man!
what is return value
Void functions have no return value
Thank you sir 🙏🏽🙏🏽
how u can work in white background xd
Lol, there are different schools of thought. A lot of people prefer white background. But I don't code in C++ and on codeblocks much so I didn't care changing the background, but my android studio is on dark theme
@@YunusKulyyev Oh thanks for your answer ^_ , anyway
that video helped me alot understand void!!
still what's the point of using a function that won't return anything ?
There is a lot of, like A lot of cases when you don't return anything. If you have a back end server you can use void function to send data and not necessarily return anything. You can display things on the screen without returning and many more
BIG THANKS MAN! do you know how to use it in more complex code that would help me understand it a lot if you show us!
Hi Hussian, thanks. You can email me at graspery@gmail.com if you have questions
Why do we use the void functions? Can't we just print out r*h in the int main function?
Hi LJ, we use functions because what if you want to print r*h 50 times? Well, you don't want to write the same code 50 times. Instead you can just write one function and use it 50 times
@@YunusKulyyev but i can insted use for loop to print 50 times right?
You can use for(int i=1 ; i
But you can do that with do while😊
nice man yeah
I want your help in making a complex program ...will you pls help me?
Hey Zainab, what is your project? I will try to help you
@@YunusKulyyev I have to made a website which has 5 parts ...in which a student can register the subjects he wanted to study in this semester along with the credit hours.We are not allowed to use any built in function.
If you have the detailed assignment, can you email it to graspery@gmail.com
Also, what language do you have to use. I don't think you will be using C++, most likely javascript
@@YunusKulyyev yeah sure..I will send you complete manual
@@YunusKulyyev it's c++
TQ bro!!!!
thanks dude!
Thank u so much
Have you tried linux ?
Yeah, mostly Ubuntu
Thank you. :-)
good video but that click sound is soo annoying
:) thanks, I'll keep that in mind
Hi
Hi!
Hi!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!
Btw thanks this was cool
Yeah of course, good luck on your programming journey