Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7496919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:51:02+00:00 2026-05-29T18:51:02+00:00

I ran into an interesting line of code today. I did not know it

  • 0

I ran into an interesting line of code today. I did not know it was legal to use the word “or”. I thought there was only ||.
What is this called and where can I read more about it?
Thanks

if (V_discount == "y" or "Y" or "Yes" or "yes")
           {
               cout << "Your discount is: ";
}

edit: It turns out the if statement doesn’t do much. I put a cout<<“hi”; in the brackets, and it executes regardless of what V_discount has in it.

I thought it was called something because netbeans is highlighting “or” in blue.

2nd edit:

v == "y" || "Y" 

is not the same as

v == "y" || v == "Y"

Only the latter functions “as intended”. “As intended” being checking whether v is the string “y” or v is the string “Y”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:51:05+00:00Added an answer on May 29, 2026 at 6:51 pm

    It’s called an “alternative token”, documented in section 2.6 [lex.digraph] of the current ISO C++ standard, and in section 2.5 of the 1998 ISO C++ standard. (This is the same section that defines “digraphs”, such as <% for { and %: for #.)

    But the code you’ve shown uses it incorrectly.

    First, if x were an int, then you’d probably want this:

    if (x == 10 or x == 20 or x == 30)
    

    rather than this:

    if (x == 10 or 20 or 30)
    

    The latter is actually legal, but it means something quite different.

    And comparing strings for equality is not straightforward. If V_discount is a char* or char[], then comparing V_discount == "yes" compares pointer values, not the contents of the strings, and they’ll certainly compare unequal. If V_discount is a std::string, then I think it will work — but you still have to compare it to each of the literals individually. Otherwise, as Tony Delroy’s answer says, it compiles but does something entirely unexpected involving implicit conversions to bool.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a interesting issue today. Check out this pseudo-code: void Loop() {
I ran into an interesting iOS problem today involving a CATiledLayer. This only happend
I just ran into a piece of code that not only compiles, but gives
Ran into something interesting, want to know if I'm doing something wrong or if
I ran into an interesting (and very frustrating) issue with the equals() method today
I ran into an interesting dilemma today. I have a function that handles information
I ran into an interesting problem at work today. I got a request to
I ran into an interesting Issue today working on a Wall Feed Plugin. A
A co-worker ran into an interesting issue today, and while I think the actual,
An interesting problem I ran into today: what is the fastest way to count

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.