Confusion about the void and what it means.

I am very new to programming and confused by what void does, I know that when you put void in front of a function, it means "it does not return anything", but if the function does not return anything, then what is the writing point of the function ?? In any case, I asked this question in my homework and try to answer it, but I need help with the general concept. any help would be great, and please try to avoid technical jargon, I'm a serious beginner here.

What does this function do?

void add2numbers(double a, double b) 
    { 
       double sum; 
       sum = a + b; 
    }
+5
source share
10 answers
void ReturnsNothing() 
{
     cout << "Hello!";
}

As you can see, this function does not return anything, but this does not mean that the function does nothing.

- , . "", , "Hello" . , . , .

+8

, , "" :

int i=9;
void f() {
    ++i;
}

i .

-

void f() {
    std::cout <<"hello world" << std::endl;
}

void .

void f(int& i) {
   ++i;
}

, .

void f() {
   while(is_not_broke()) {
        //...
   }
   throw std::exception(); //it broke
}
+5

void (, , , - ..), .

+3

C/++ , "-, ". , C/++ , void, .

, , - . , (, ..).

+2

void . , exit:

void exit(int status)

, - .

+1

,

void add2numbers(double a, double b, double &sum) 
{        
   sum = a + b; 
}

, ,

, , , , .

bool sqrt(double value, double &answer)
{
   if value < 0.0 ) {
      return false;
   } else {
      answer = real_sqrt_function(value);
      return true;
   }
}
+1

- , - , - .

, void, , " ". , - , . , .

+1

; , . , , ( ). , x y Move, xDelta yDelta.

Move 2, 3 2 X 3 Y. , , Move, .

+1

, VTK. void , . void GUI Qt. , , .

0

: , , - . , , "" , .

, , : Haskell. , , , . , Haskell, , .

my_tan(x) = sin(x)/cos(x)          -- or (preferred):    tan' x = sin x / cos x

++

double my_tan(double x) { return sin(x)/cos(x); }

, , ? - , , - , , .. Haskell , IO . , putStrLn, , String -> IO(). : String IO, main, ( () void ++).

IO , : IO, . ++ void putStrLn(std::string), "" -, , , . , , , IO ( ). , , " "! IO.

0
source

All Articles