Answer the question
In order to leave comments, you need to log in
Can't understand what is VOID in C++?
I don't really understand what it's about. It is possible on examples for the beginner that it would be more clear.
Answer the question
In order to leave comments, you need to log in
You can think void
of it as an empty or undefined value.
For example, it can be used:
void print_hello()
{
printf("Hello!");
}
print_hello()
you can also write this: print_hello(void)
void
omitted when writing)void *value; // указатель на что-то неопределенное
int a = 5;
value = (int *)a; // теперь указываем на целое
void
, otherwise - the return data type. And that's it: you shouldn't bother yourself with this anymore
do you see the bagel? you perform a function and eat it. what do you have left of the donut? true? false? null? void!
void is specified as the return type of a function if it returns nothing. For example, the int get_speed() function, which returns the unit's speed as an integer, is defined with type int. But void set_speed(int speed) does not return anything, but rather sets the speed. That's why we use void.
Vlad Convoy It's simple. From the course Computer science. I recommend reading SICP!!!
In mathematics To the question "What does it look like?" replies "function". And to the question "How to get it?" The answer is "procedure".
In C-like languages, named computations are written as functions. But functions in C-like languages answer both questions, and there is no way to tell the difference. A function in C-likes must always return something! Some result! Some new object. But something new must be returned anyway!
Now, what if you want to at least somehow distinguish between functions and procedures? Here for this there is a "crutch" in the form of 'void'! In other words, it's a way of saying to the reader of the code, "we're not returning anything, we're only creating." This is "how to get it?" in such functions only the production of something new. Draw a window, encrypt a disk, send it to a friend .... And in the functions that return the result, you can already write in terms of mathematics, that is, what it looks like, but not how it turns out;)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question