+ 1
can any one define void in a short way..?
void is a bassic data type that defines a valuless stats.... what dose it mean by valueless cany any one explain it in short way... Regards.
7 Answers
+ 4
A void function shows that there is no return.
+ 3
void means return nothing and just do what I want
+ 2
Basically it means "nothing" or "no type"
Function return value: void myFunc(int) -- the function returns nothing
+ 2
void setAttr(int n) //returns nothing
int getAttr(void) //takes no parameter
+ 2
srry..IDK
+ 1
EDIT: Sorry, I just realized you wanted a short explanation. This is not exactly short, but I hope it helps.
void is used when a function returns nothing.
for example:
void myFunc() {
cout << "Hello" << endl;
}
When called, myFunc() doesn't return anything, it just prints something to the screen ("Hello").
int is used when a function returns an integer.
ie:
int myOtherFunc() {
return 42;
}
When called, myOtherFunc() returns 42. You can use the return value, for example:
- assign it to a variable:
int number = MyOtherFunc(); // here number will be equal to 42
- or you can do operations on it:
int sum = myOtherFunc() + 10; // here sum will be equal to 52
You couldn't do that with a void function.
The same works with other data types, you can have a function that returns a boolean, in this case the function will be something like bool func(){return true;}.
Etc.
The functions I used as exemples have no parameters, but it also works otherwise. Just keep in mind that the data type of the function is not related to the data types of the parameters, you can make a function that returns nothing but takes an integer, ex: void func(int number);, or a function that returns an integer but takes two floats, ex: int func(float number, float number2);.
This is a very basic explanation but I hope it helps.
+ 1
thank you #koshe