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

  • Home
  • SEARCH
  • 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 9004037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:48:39+00:00 2026-06-16T00:48:39+00:00

Sometimes I want to do something like this (with i and j being ints).

  • 0

Sometimes I want to do something like this (with i and j being ints).

(if i==4 && j==9)
{
   ...
}

Where it’ll go through the brackets if i equals 4 and j equals 9. I’ve been using a single ampersand (&) instead of a double one and my code’s been compiling and running.

Is it doing the same thing as a double ampersand &&, and if not what has it been doing?

Edit: Oh and I’ve been doing the same thing with or, using ‘|’ instead of ‘||’

  • 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-06-16T00:48:40+00:00Added an answer on June 16, 2026 at 12:48 am

    Presumably you mean if (i==4 && j==9).

    Under the circumstances, changing this from && to & shouldn’t change much. The big thing that’ll change is that with &&, the j==9 would only be evaluated if the i==4 part was true, but with &, they’ll both be evaluated regardless.

    When you have something like if (x != NULL && x->whatever ...) you want to ensure that the second part (that dereferences x) is only evaluated if x is not a null pointer. In your case, however, comparing what appear to be ints is unlikely to produce any problems.

    It’s also possible to run into a problem when you’re dealing with something that may produce a value other than 1 to signal true. Again, it’s not a problem here because == will always produce either 0 or 1. If (for example) you were using isalpha, islower, etc., from <ctype.h>, they’re only required to produce 0 or non-zero values. If you combined those with a &, you’d get a bit-wise or which could produce 0 for two non-zero inputs (e.g., 1 & 2 == 0, but 1 && 2 == 1).

    When you use bitwise and on the results from ==, you’re going to get 0 & 0 or 0 & 1 or 1 & 0 or 1 & 1. 1 & 1 will yield 1 (true). All the others will yield 0 (false) — just like && would have.

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

Sidebar

Related Questions

I know subversion but sometimes I want something simpler like plain old files with
I want to do something like this: In case 1: content height is smaller
I want to do something like this: SELECT Users.id, Countries.name FROM Users, Countries WHERE
Sometimes, I want to use an ObjectOutputStream to write something to a file or
When using implicit waits, as advised here , I still sometimes want to assert
When we have something like this: interface ISomething<U,V> { ... } class Something<U,V> :
In the Modern Objective-C runtime, you can do something like this: @interface MyClass :
I have something like this in my code typedef struct ts_fem_mesh { double **vertices;
Got question. If i make query to server i use something like this: mysql_query(select
Apologies if this seems like I want my problem saved for me, but I

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.