Questions tagged [operators]
Regarding programming languages, operators are constructs which behave generally like functions, but which differ syntactically or semantically from usual functions. From Wikipedia: http://en.wikipedia.org/wiki/Operator_%28programming%29
                87 questions
            
            
            
                0
            
            votes
        
        
            
                1
            
            answer
        
        
            
                731
            
            views
        
        
            
            
            
        In C/C++ and Java, why does dividing an integer by an integer return an integer, while in other languages, it returns a decimal value? [closed]
                    I have found another similar question, but the answer there talks mainly about C/C++, and does not mention about the division operator. So, in C/C++ and Java, dividing an integer by an integer returns ...
                
            
       
        
            
                1
            
            vote
        
        
            
                3
            
            answers
        
        
            
                480
            
            views
        
        
            
            
            
        What is the problem with a range operator?
                    Virtually all (imperative) languages offer the operators < <= >= > for lower, lower or equal, greater or equal and greater. But why no ternary range operator like (10 < x < 100) to ...
                
            
       
        
            
                2
            
            votes
        
        
            
                3
            
            answers
        
        
            
                515
            
            views
        
        
            
            
            
        C# Duplicated usage of an if/else condition and a ternary operator. A good practice?
                    I had a debate with a work mate regarding the following code as to which one of it would be the better practice:
My code (in pseudo):
var A = <precondition either TRUE or FALSE>;
var B;
if(A)
{
 ...
                
            
       
        
            
                0
            
            votes
        
        
            
                1
            
            answer
        
        
            
                305
            
            views
        
        
            
            
        Excessively verbose and cryptic comparisons in Java
                    I don't know if this is the right place to ask more of a "philosophical" question.
The more I code in Java, the more I have to bear with Comparable<T>. And the more I bear with this ...
                
            
       
        
            
                0
            
            votes
        
        
            
                4
            
            answers
        
        
            
                287
            
            views
        
        
            
            
            
        Language design : use equals symbol = both for affectation and comparison, like in MySQL
                    I'm currently designing a database query language and I came to wonder what should be the best syntax for the comparison operator.
Most modern languages use ==, but amongst the database languages ...
                
            
       
        
            
                18
            
            votes
        
        
            
                3
            
            answers
        
        
            
                2k
            
            views
        
        
            
            
            
        Should wrappers compare as equal using the == operator when they wrap the same object?
                    I'm writing a wrapper for XML elements that allows a developer to easily parse attributes from the XML. The wrapper has no state other than the object being wrapped.
I am considering the following ...
                
            
       
        
            
                3
            
            votes
        
        
            
                1
            
            answer
        
        
            
                221
            
            views
        
        
            
            
            
        Should equality operators be approximate when defining numeric types that rely on floating-point numbers?
                    For example, say you have a class Point which has floating point components. It's tempting to overload the equality operator so you can do something like
a = Point(1.1, 2.2)
b = Point(3.3, 6.6)
b /= ...
                
            
       
        
            
                5
            
            votes
        
        
            
                7
            
            answers
        
        
            
                4k
            
            views
        
        
            
            
            
        Why don't languages use the words "and" and "or" instead of "&&" and "||"?
                    When I was a beginner it took a while to learn the language syntax and the idea that languages couldn't improve after they were invented. 
But now we're seeing new language features added every year ...
                
            
       
        
            
                2
            
            votes
        
        
            
                1
            
            answer
        
        
            
                292
            
            views
        
        
            
            
            
        Good way to do 3D vector math in language without operator overloading
                    I would like to make a simple web application (a static website where all computation happens on the client) that generates a mesh and displays it. I have a working prototype in Unity and now I'm ...
                
            
       
        
            
                1
            
            vote
        
        
            
                2
            
            answers
        
        
            
                1k
            
            views
        
        
            
            
            
        Solving issues in using post and pre increment operators as part of expressions
                    I recently had a discussion with a friend about code maintainability with regards to modifying an iterator inside of the body of a loop (C# syntax):
List<int> test = new List<int>();
for (...
                
            
       
        
            
                0
            
            votes
        
        
            
                2
            
            answers
        
        
            
                996
            
            views
        
        
            
            
            
        Why was the caret used for exponentiation in BASIC?
                    As far as I have been able to find, the first language to use ^ for exponentiation was BASIC, in 1964. Earlier languages, such as Fortran, used other symbols such as ** for exponentiation (although in ...
                
            
       
        
            
                3
            
            votes
        
        
            
                1
            
            answer
        
        
            
                120
            
            views
        
        
            
            
            
        Should I replace a constant with static methods, if that constant usually 'cooperate' with a specific operator?
                    For example, to convert between g and kg, I have a constant 1000:
public static final float G_TO_KG=1000;
.
.
.
this.result = someResult*1000;
I found G_TO_KG always bind to operator '*'. So my ...
                
            
       
        
            
                2
            
            votes
        
        
            
                4
            
            answers
        
        
            
                4k
            
            views
        
        
            
            
        Why does C provide both the comma operator and the semicolon to separate statements?
                    Both the comma operator and the semicolon can be used to separate statements. Let's consider this simple code:
#include <stdio.h>
void do_something(int*i) {(*i)++;}
int main() {
    int i;
   ...
                
            
       
        
            
                58
            
            votes
        
        
            
                8
            
            answers
        
        
            
                20k
            
            views
        
        
            
            
            
        Is there a keyword or operator for "nor"?
                    Is there an operator equivalent of nor? For example, my favorite color is neither green nor blue. 
And the code would be equivalent to: 
// example one
if (color!="green" && color!="blue") { ...
                
            
       
        
            
                62
            
            votes
        
        
            
                3
            
            answers
        
        
            
                11k
            
            views
        
        
            
            
            
        && and || are not logical but conditional operators?
                    I am a bit confused by the MSDN C# documentation which states that & and | are logical operators and that && and || are conditional operators.
I keep calling &&, || and ! logical ...
                
            
       
         
         
         
         
        