+ 1
int a = 14;int b = 23; if (a&& b) cout << a; else cout << b; can some body tell my what will be the output and explain pl
15 Respuestas
+ 4
ans=14
bcoz
&& operator says
if both sides are true the value is true
here in this example
14&&23
means
true&&true
bcoz compiler understand all digits true without 0(false)
if u give value of variable a is 0 then the condition is false and else part is executed
+ 3
If it's JavaScript, the output will be a because every number other than zero is true.
+ 3
Maybe I'm wrong, but I think 1 is true and 0 is false. So if a and b both are one, then it will be true, and the if statement will execute. If not, the if statement will not execute.
+ 3
@J.G. Any number other than zero is true. It's not just 1.
+ 3
@Cheeze But before, you said in JavaScript. Is it just in js or in all languages?
+ 3
@J.G. Since I only know JS, I never try it in any other languages. I believe it works the same as other languages but who knows I might be wrong.
+ 3
@Cheeze I've never tried it either. I only know java and c++
Going to try it in those languages now...
+ 3
Output is 14. The condition is true.
"negative or positive. Anything that's not a 0 is a true value in if"
source: http://stackoverflow.com/questions/14646718/if-statement-integer
+ 3
@Jafca That makes sense, but I tried it, and if something other than 1 is put in, it doesn't work.
+ 3
@J.G. You can enter two numbers here and try it
https://code.sololearn.com/cERaMkI4gq7n/?ref=app
+ 3
@Jafca I just realized I had a nested if statement that wasn't supposed to be. My logic in the program then gave me the wrong answer. That makes sense.
+ 3
!
@Sultan That's what we have been figuring out. It will be the same in c++
:)
0
it is a c++ code guys not JavaScript
- 1
its a c++ code!
- 2
the outpur of this will be an error as you are asking an if without any parameters, you are just saying ( if a and b ) ?????? you need to supply some parameters for the program to check, etc if a and b larger than three (then) some code ( else ) some code.