locked
or operation in C++ RRS feed

  • Question

  • DWORD tempAttributes = 4;
    tempAttributes = tempAttributes||1;

    I do above or operation but I am getting always 1 but not 5.

    What is wrong with it? What is bug?

    Sunday, November 29, 2020 5:11 PM

All replies

  • It appears that you are expecting a bitwise OR instead of a logical OR.

    Bitwise is written with a single pipe |. This will return 5 as expected.

    Logical is written with two pipes ||. This returns true or false (1 or 0).

    • Proposed as answer by WayneAKing Sunday, November 29, 2020 6:53 PM
    Sunday, November 29, 2020 5:34 PM
  • Note that this forum is for C# (C Sharp) issues, not C++.

    The MSDN forums for C++ have been closed for new posts.
    C++ questions should now be asked in the Q&A forums:

    https://docs.microsoft.com/en-us/answers/topics/c++.html

    Note that this MSDN forum is also closing soon. New threads for C# issues
    should be posted in Q&A as well:

    https://docs.microsoft.com/en-us/answers/topics/dotnet-csharp.html

    - Wayne

    Sunday, November 29, 2020 6:53 PM
  • Hi,

    Has your issue been resolved?

    If so, please click on the "Mark as answer" option of the reply that solved your question, so that it will help other members to find the solution quickly if they face a similar issue. If you still have questions, please feel free to ask.

    Best Regards,

    Timon


    "Visual C#" forum will be migrating to a new home on Microsoft Q&A ! We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A ! For more information, please refer to the sticky post.

    Thursday, December 3, 2020 7:26 AM