472,958 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1444
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:
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.