+ 2

if(!(age>16))

ā™¢If I wright this logical not operator like this-- if(age>!16)...so to this formatte is there any problem ?

8th Apr 2018, 6:45 AM
S M Rakibul Alam
S M Rakibul Alam - avatar
5 Answers
+ 5
What language are you using?
8th Apr 2018, 6:50 AM
Ibaadi Jaya
Ibaadi Jaya - avatar
+ 5
You probably have an exception or an unexpected result. The problem is that you are using a logical operator on another type of data. In the expression if(age> 16) you will get a boolean result (true or false) and the operator not (!) Is responsible for transforming the value returned in its counterpart. In the case that you expose two things can happen: 1. The language can "scold" you for what you try to do with the operator (it will give you an error, in other words). 2. The language will evaluate the number as true or false and change it to one of those values (or to 0/1). Remaining the expression like this: Ā Ā Ā Ā  if (age> 0) | if (age> 1) | if (age> false) | if (age> true)
8th Apr 2018, 7:21 AM
Mickel
Mickel - avatar
+ 4
If you want to express "age not larger than 16" then you can use the less than operator "<" or less than or equal to operator "<=" instead; if(age < 16) if(age <= 16) Easier to read and understand I guess...
8th Apr 2018, 9:23 AM
Ipang
+ 1
C++
8th Apr 2018, 7:14 AM
S M Rakibul Alam
S M Rakibul Alam - avatar
+ 1
What language ate you useing. Depending on the language multiple thinhs could be happening. The mosy likely problem is that "!" exspects a boolean not an int. This means !16 is invalid or false depending on the language. In short evem if it runs it will not give the desired logical output.
8th Apr 2018, 7:34 AM
josh mizzi
josh mizzi - avatar