operators

How do you read this JavaScript code? (var1 ? var2:var3)

I've seen this format used in JavaScript code, but can't find a good source for the meaning. Edit for a follow-up: Thanks for all the quick answers! I figured it was something like that. Now, for bonus points: can you use (var1 ? var2) to do the same thing as if (var1) { var2 } ? ...

Combobox with comparison operators

I actually have an equation to make on visual basic. An exemple of it (12 = 12) AND (12>1) true and true the answer would be TRUE But for both comparison operators i must create a combo box to insert <, >, =, <=, >=, <> My problem is my program wont function because I don't know which variable to use for those... could anyo...

C#: What needs to be overriden in a struct to ensure equality operates properly?

As the title says: do i need to override the == operator? how about the .Equals() method? Anything i'm missing? ...

Why does a "&&=" Operator not exist?

(a && b) has the same value as (a & b), but with && the expression b is not executed if a is false. In Java there is also an operator &=. a &= b is the same as a = a & b. Question: Why isn't there an operator &&=, at least in Java. Is there some reason why I would not make sense to have it, or is it simply that no one cares or needs it...

Is the ^ operator really the XOR operator in C#?

I read that the ^ operator is the logical xor operator in c#, but i also thought it was the "power of" operator. Can someone clear this up for me? ...

JRXML operator error

Hi everyone, I'm getting this error when compiling my JRXML file in iReport 3.1.2: com.jaspersoft.ireport.designer.errorhandler.ProblemItem@f1cdfb The operator > is undefined for the argument type(s) java.lang.Integer, java.lang.Integer net.sf.jasperreports.engine.design.JRDesignExpression@eb40fe The only place in my entire report wh...

Can you make custom operators in C++?

Is it possible to make a custom operator so you can do things like this? if ("Hello, world!" contains "Hello") ... Note: this is a separate question from "Is it a good idea to..." ;) ...

Multiple output operators?

Hi, is it possible to define multiple output operators for an enum? I want to use this std::ostream& operator<< (std::ostream& os, my_enum e); operator to (1) print a human readable text and to (2) convert it to some code for storing in a database. Thanks ...

What are the best practices for implementing the == operator for a class in C#?

While implementing an == operator, I have the feeling that I am missing some essential points. Hence, I am searching some best practices around that. Here are some related questions I am thinking about: How to cleanly handle the reference comparison? Should it be implemented through a IEquatable<T>-like interface? Or overriding object...

What _did_ the C operators /\ and \/ do?

Anyone can "declare" ones own operators in C.... that is if one is a C compiler guru and has the source code to the C compiler! ;-) Further questions to puzzle: How are these operations done in C99? gcc? ... And why were /\ & \/ dropped? Which types were the /\ and \/ operators valid for? Googling for "/\ \/" naturally returns nothi...

One position right barrel shift using ALU Operators?

I was wondering if there was an efficient way to perform a shift right on an 8 bit binary value using only ALU Operators (NOT, OR, AND, XOR, ADD, SUB) Example: input: 00110101 output: 10011010 I have been able to implement a shift left by just adding the 8 bit binary value with itself since a shift left is equivalent to multiplying...

Understanding the "||" OR operator in If conditionals in Ruby

Just briefly, why are the following three lines not identical in their impact? if @controller.controller_name == "projects" || @controller.controller_name == "parts" if @controller.controller_name == ("projects" || "parts") if @controller.controller_name == "projects" || "parts" The first gives me the result I want, but as there's a...

Validity of the Java Code

double ABC = - UTIL_COMMON.fnChkDouble(lStr); Above statement, is it valid or not? Thanks ...

why = operator works on structs without having been defined?

lets put a simple example: struct some_struct { std::string str; int a, b, c; } some_struct abc, abc_copy; abc.str = "some text"; abc.a = 1; abc.b = 2; abc.c = 3; abc_copy = abc; then abc_copy is an exact copy of abc.. how is it possible without defining the = operator? (this took me by surprise when working on some code..) ...

Java operator overloading

Not using operators makes my code obscure. (aNumber / aNother) * count is better than aNumber.divideBy(aNother).times(count) After 6 months of not writing a single comment I had to write a comment to the simple operation above. Usually I refactor until I don't need comment. And this made me realize that it is easier to read and pe...

what is the official name of C++'s arrow (->) operator?

I think the subject says it all. I always call it the "arrow operator", but I'm sure it has an official name. I quickly skimmed the C++ standard and didn't see it mentioned by name. ...

Learning by example - terminology (?, :, etc)

When you were a kid, did you ever ask your parents how to spell something and they told you to go look it up? My first impression was always, "well if could look it up I wouldnt need help spelling it". (yeah yeah I know phonetics) ...anyway, I was just looking at some code and I found an example like: txtbx.CharacterCasing = (checkb...

Logical xor operator in c++?

Is there such a thing? First time I encountered a practical need for it, but I don't see one listed in stroustrup. I intend to write: // Detect when exactly one of A,B is equal to five. return (A==5) ^^ (B==5); But there is no ^^ operator. Can I use bitwise ^ here and get the right answer (regardless of machine representation of true ...

Index, assignment and increment in one statement behaves differently in C++ and C#. Why?

Why is this example of code behaving differently in c++ and C#. [C++ Example] int arr[2]; int index = 0; arr[index] = ++index; The result of which will be arr[1] = 1; [C# Example] int[] arr = new int[2]; int index = 0; arr[index] = ++index; The result of which will be arr[0] = 1; I find this very strange. Surely there must be so...

Can Ruby operators be aliased?

I'm interested in how one would go in getting this to work : me = "this is a string" class << me alias :old<< :<< def <<(text) old<<(text) puts "appended #{text}" end end I'd like that when something gets appended to the me variable, the object will use the redefined method. If I try to run this, I get syntax error, une...