We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
C++ allows for integers to be treated as logical values. If the integer is non-zero, it's "true" and if the integer is zero it's "false". The ! is the logical-not operator and the language standard says !0 will be equal to 1.
A similar rule holds for max == n. Whenever, that expression evaluates to "true" it will also represent the numerical value 1.
Assignments, such as max = n, also have the side-effect of "returning" the assigned value (n in this case).
Therefore, this is a really terse way of writing:
if(max<n){max=n;c=1;}elseif(max==n){c+=1;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Birthday Cake Candles
You are viewing a single comment's thread. Return to all comments →
C++ allows for integers to be treated as logical values. If the integer is non-zero, it's "true" and if the integer is zero it's "false". The
!
is the logical-not operator and the language standard says!0
will be equal to 1.A similar rule holds for
max == n
. Whenever, that expression evaluates to "true" it will also represent the numerical value 1.Assignments, such as
max = n
, also have the side-effect of "returning" the assigned value (n in this case).Therefore, this is a really terse way of writing: