Is there any significance to this return statement?

I was wondering if there is any value in the part of the code that I see that includes

return (num!=0);

where num is int. And this is the return statement of a boolean function that wants to return TRUE if num != 0and false if num = 0.

I am not sure if there is a hidden meaning for this, but I don’t see why they simply cannot just write:

return num;

Here is the code I saw:

bool SemClass::cut(int &a, int &b, int &c) 
{
  int num = 0;    
  check(a, num);
  check(b, num );
  check(c, num);
  return (num != 0);
}
+4
source share
3 answers

0 , null-- boolean . , 1, 2, 3, 4 .., true. C ; C .

: en.cppreference.com/w/cpp/language/implicit_cast

, ++, num num!=0 . num!=0 , . 0 , . num!=0, , true, num 0 false, .

, , boolean, , . integer code/enum.

, num!= num . . , integer, boolean.

+6

, return num, . , , .

return num, , num int, bool, (s), ( ++), , 0 -> false, anything else -> true. , ?

return num!=0, (s), , ( , ) , .

, , , ( ) . , , , (r-). ++ 20 , , , ( , ).

+2

() :

  • .

  • ++ bool: , false, true.

return num;, .

( , C int 1 0, true false).

+1

Source: https://habr.com/ru/post/1628798/


All Articles