operators

What is the diffference between the | and || or operators?

I have always used || (two pipes) in OR expressions, both in C# and PHP. Occasonally I see a single pipe used: | What is the difference between those two usages? Are there any caveats when using one over the other or are they interchangeable? ...

What does the ',' operator do in C?

What does the ',' operator do in C? ...

How do the equality (== double equals) and identity (=== triple equals) comparison operators differ?

Can you explain the difference between == and ===, giving some useful examples? ...

relational operator expression order

This is probably a silly question, but curiosity has gotten the better of me. I've been seeing code lately that seems to "reverse" the order of expressions for relational operators e.g.: if (0 == someVariable) As opposed to what I normally see/write: if (someVariable == 0) To me, the second method seems more readable and intuitive,...

Why Does Ruby Only Permit Certain Operator Overloading

In Ruby, like in many other OO programming languages, operators are overloadable. However, only certain character operators can be overloaded. This list may be incomplete but, here are some of the operators that cannot be overloaded: !, not, &&, and, ||, or ...

Dynamically created operators

I created a program using dev-cpp and wxwidgets which solves a puzzle. The user must fill the operations blocks and the results blocks, and the program will solve it. Im solving it using bruteforce, i generate all non repeated 9 length number combinations using a recursive algorithm. It does it pretty fast. Up to here all is great! But t...

How to prevent creating intermediate objects in cascading operators?

I use a custom Matrix class in my application, and I frequently add multiple matrices: Matrix result = a + b + c + d; // a, b, c and d are also Matrices However, this creates an intermediate matrix for each addition operation. Since this is simple addition, it is possible to avoid the intermediate objects and create the result by addi...

How do I get a decimal value when using the division operator in Python?

For example, the standard division symbol '/' rounds to zero: >>> 4 / 100 0 However, I want it to return 0.04. What do I use? ...

Suppress error with @ operator in PHP

In your opinion, is it ever valid to use the @ operator to suppress an error/warning in PHP whereas you may be handling the error? If so, in what circumstances would you use this? Code examples are welcome. Edit: Note to repliers. I'm not looking to turn error reporting off, but, for example, common practice is to use @fopen($file); ...

PHP alias @ function

I'm new to PHP and I'm confused seeing some examples calling a function with a @ prefix like @mysql_ping(). What is it for? Googling / searching is not much of a help since @ gets discarded and 'alias' is not good enough keyword. ...

Absolute Beginner's Guide to Bit Shifting?

I've been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same operators) ... What I'm wondering is, at a core level, what does bit-shifting (<<, >>, >>>) do, what problems can it help solve, and what gotchas lurk around the bend? In other words, an absolute beginner's g...

What does the code if ( blah(), 5) {} do?

What does the following code do in C/C++? if ( blah(), 5) { //do something } ...

Priority of C++ operators "&" and "->"

Given the following: &row->count Would &(row->count) be evaluated or (&row)->count be evaluated in C++? EDIT: Here's a great link for C++ precedence. ...

What's the deal with all the different Perl 6 equality operators? (==, ===, eq, eqv, ~~, =:=, ...)

Perl 6 seems to have an explosion of equality operators. What is =:=? What's the difference between leg and cmp? Or eqv and ===? Does anyone have a good summary? ...

Boolean 'NOT' in T-SQL not working on 'bit' datatype?

Trying to perform a single boolean NOT operation, it appears that under MS SQL Server 2005, the following block does not work DECLARE @MyBoolean bit; SET @MyBoolean = 0; SET @MyBoolean = NOT @MyBoolean; SELECT @MyBoolean; Instead, I am getting more successful with DECLARE @MyBoolean bit; SET @MyBoolean = 0; SET @MyBoolean = 1 - @MyBo...

What does the C# operator => mean?

Answers to a recent post (Any chances to imitate times() Ruby method in C#?) use the => operator in the usage examples. What does this operator do? I can't locate it in my C# book, and it is hard to search for symbols like this online. (I couldn't find it.) ...

In Python, what is the difference between '/' and '//' when used for division?

Is there a benefit to using one over the other? They both seem to return the same results. >>> 6/3 2 >>> 6//3 2 ...

K & R Question: Need help understanding "getbits()" method in Chapter 2

As I've mentioned before, I'm going through K&R, and overall am doing all right with it. However, in chapter 2, the section on bitwise operators (section 2.9), I'm having trouble understanding how one of the sample methods works -- and as a result, I'm having trouble with the associated exercises. (This isn't a dupe of my prior questio...

Why don't C++ compilers define operator== and operator!= ?

I am a big fan of letting the compiler do as much work for you as possible. When writing a simple class the compiler can give you the following for 'free': A default (empty) constructor A copy constructor A destructor An assignment operator (operator=) But it cannot seem to give you any comparison operators - such as operator== or o...

FizzBuzz using Ternary Operator

I've been reading up on conditional style expressions in ruby, however I came across one I couldn't quite understand to define the classic FizzBuzz problem. I understand the FizzBuzz problem and even wrote my own before finding the following quick solution utilising the ternary operator. If someone can explain to me how this chain works ...