Solved

& and && ?

Posted on 2003-10-27
1
173 Views
Last Modified: 2010-04-02
To C++ Experts,
  How do I calculate these :
------------------------------
   int z = x & y ;
   int w = x && y ;
------------------------------
  if x and y are both integers, how do I calculate z and w ?
  thanks.
0
Comment
Question by:meow00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 19

Accepted Solution

by:
Dexstar earned 40 total points
ID: 9629858
meow00:

>   How do I calculate these :
>    int z = x & y ;
>    int w = x && y ;
>   if x and y are both integers, how do I calculate z and w ?

"&" is a bit-wise operator.  Here is a description of how it works:
      http://www.codeproject.com/cpp/bitbashing.asp

"&&" is a logical "and" operator.  Basically it works like this:

A && B = X

     If A is true (not 0) AND B is true, then X will be True (1).
     If either A or B is not true (equal to 0), then X will be False.

Hope that helps,
Dex*
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 167
Getting IP address 8 100
FMX enumerated colours 2 133
Embarcadero C++ builder XE10.1 Berlin TRegistry declaration 1 48
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question