473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

& and && operator confusion

100 100+
Hi,


I have a code...
Expand|Select|Wrap|Line Numbers
  1.     int t=0x40000006,y=0x000000ff,i=0x40000000,a=0xf0000000;
  2.     cout<<(t&y);
  3.     cout<<"\n";
  4.     if(m1=i&&(t&y))
  5.         cout<<"Here"<<i&&(t&y);
  6.     if(h=((t&a)==(m1=i&&(t&y))))
  7.         cout<<"here"<<h<<endl<<m1;
  8.     cin>>x;
  9. }
  10.  

here cout<<"Here"<<i&&(t&y); gives 0x40000000 as output


My question is 0x40000000 && 0x00000006 gives 0x40000000...Why??

Can anyone please explain.....
Jun 7 '07 #1
3 1464
DeMan
1,806 1GB
& is a bitwise operator
&& is a logical operator

For a logical operator there are only two values - true and false. Usually, c will treat 0 as false and ANYTHING else as true, so 0x40000000 && 0x00000006 will return true (since both are non-zero) (I don't think it's guaranteed to give 0x40000000, but it may do).

The bitwise operator doews a logical 'and' on EVERY bit thus
Expand|Select|Wrap|Line Numbers
  1. 0x04 & 0x0c == 0x04
  2.  
Jun 7 '07 #2
rag84dec
100 100+
i am using visual studio 6.0 and my question is for && operator.
i&&(t&y) gives 0x40000000 y???
Jun 7 '07 #3
DeMan
1,806 1GB
because && return true or false - which can be implementation specific.

i&y makes 0x00000006 (as you expect)

0x40000000&& 0x00000006 (both are non zero) so the result is true (which is any non-zero value). In this particular case, the implementer has decided to return your first term
Jun 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
21
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as...
2
by: TonyM | last post by:
Q: Is there a good way to overcome this apparent bug without modifying the mfc code? ___________________________________ Info: Although it is NOT a good idea, I seemed to have perhaps located a...
11
by: Xiaoshen Li | last post by:
Dear Sir, I am a little puzzled about a function returning a class object, for example, suppose I hava a class Money and a method: Money lastYear(Money aMoney) { Money tempMoney; ......
6
by: Geoffrey S. Knauth | last post by:
It's been a while since I programmed in C++, and the language sure has changed. Usually I can figure out why something no longer compiles, but this time I'm stumped. A friend has a problem he...
17
by: Bruce One | last post by:
Lets consider a class called Currency. This class must be the responsible for taking care of all calculations over currency exchanges, in such a way that I pass values in Euros and it returns the...
2
by: Ian | last post by:
1. I want to be use mix unmanaged code with managed code. In particular, the unmanaged code uses MFC CFile to perform file I/O. Can CFile be used in unmanaged code that is mixes with managed...
3
by: Tony | last post by:
I see that many pages have &amp; in querystring instead &. What is difference? Can I put page link (url) www.mysite.com/mypage.aspx?lang=EN&ID=15 or I need to write...
1
by: developereo | last post by:
Hi folks, Can somebodyshed some light on this problem? class Interface { protected: Interface() { ...} virtual ~Interface() { ... } public:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.