Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
What does if(!a>="some number") mean?
is it same as if a is not greater than or equal to some number ??????
Like what will be the outcome of following?

C#
#include<iostream>
using namespace std;
int main()
{
	int a=500,
	b=100,
	c;
	if(!a>=600)
	b=300;
	c=200;
	cout<<b<<c;
	return 0;
}


What I have tried:

I tried understanding it as follow

if a is not greater than or equal to some number
so according to me it satisfies the following that a is not greater than or equal to 600 as it is initialised to 500, So b should change its value from 100 to 300.
plz tell where i am going wrong?
Posted
Updated 6-Dec-16 21:20pm
v3
Comments
CHill60 6-Dec-16 13:15pm    
Is 'a' a numeric?
Member 12890185 6-Dec-16 13:18pm    
yes
the actual question is
#include<iostream>
using namespace std;
int main()
{
int a=500,
b=100,
c;
if(!a>=600)
b=300;
c=200;
cout<<b<<c;
return 0;
}
Patrice T 6-Dec-16 13:24pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Member 12890185 6-Dec-16 13:26pm    
@ppolymorphe
I have updated it now..
please help me out..
[no name] 6-Dec-16 13:30pm    
"what will be the outcome of following?", run it and find out for yourself. Why are you making things so complicated? if (a < 600)

1 solution

It is all about operator precedence
C++ Operator Precedence - cppreference.com[^]
! have higher precedence than >=
It means that
C++
if(!a>=600)

is
C++
if((!a)>=600)

and in C 0 means false and any values not zero is true
so for a=500, !a is 0 and you have
C++
if(0>=600)
 
Share this answer
 
v2
Comments
CPallini 6-Dec-16 15:51pm    
5.
Patrice T 6-Dec-16 15:53pm    
Thank you.
CHill60 6-Dec-16 19:08pm    
5'd. I'd originally posted a C# response and realised I was being unobservant. Called myself a few names and deleted my solution (hence yours is "2")
Patrice T 6-Dec-16 19:13pm    
Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900