Solved

& and && ?

Posted on 2003-10-27
1
175 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

Industry Leaders: 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

630 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